Main page
New page
Upload file
Help
Community portal
Recent changes
Talk
Contributions
Create account
Enable dark mode
Enable read mode
Log in
View history
What links here
Related changes
Page information
Editing
Template:Random number/doc
From Appropedia
Are you familiar with
Appropedia's template guidelines
?
Warning!
You are not logged in.
Log in
or
create an account
to have your edits attributed to your username rather than your IP, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{documentation subpage}} This template generates a [[pseudo-random]] integer between 0 and ''count''-1. ; Usage<nowiki>:</nowiki> * <tt><nowiki>{{</nowiki>Rand<nowiki>|</nowiki></tt>''count''<tt><nowiki>|</nowiki></tt>''seed''<tt><nowiki>|</nowiki></tt>''prime''<tt><nowiki>}}</nowiki></tt> * All parameters are optional and have default values. They must be integers. * The default ''count'' is 100 (so by default, this template generates values between 0 and 99) and must be non-zero. * The default ''seed'' is <nowiki>{{#time:z}}</nowiki> and can be set to any other integer value (used to generate distinct values on the same page). * The default ''prime'' is 67 and should be a [[prime number]] above 17 (used to generate distinct values on the same page). ; Examples generating numbers between 0 and 999<nowiki>:</nowiki> * <tt><nowiki>{{Rand|1000}}</nowiki></tt> = {{Rand|1000}} * <tt><nowiki>{{Rand|1000|</nowiki>{{#time:z}}<nowiki>|67}}</nowiki></tt> = {{Rand|1000|{{#time:z}}|67}} (same as above) * <tt><nowiki>{{Rand|1000|</nowiki>{{#time:z}}<nowiki>|61}}</nowiki></tt> = {{Rand|1000|{{#time:z}}|61}} (this and others should all be different) * <tt><nowiki>{{Rand|1000|6}}</nowiki></tt> = {{Rand|1000|6}} * <tt><nowiki>{{Rand|1000|5}}</nowiki></tt> = {{Rand|1000|5}} * <tt><nowiki>{{Rand|1000|4}}</nowiki></tt> = {{Rand|1000|4}} * <tt><nowiki>{{Rand|1000|3}}</nowiki></tt> = {{Rand|1000|3}} * <tt><nowiki>{{Rand|1000|2}}</nowiki></tt> = {{Rand|1000|2}} * <tt><nowiki>{{Rand|1000|1}}</nowiki></tt> = {{Rand|1000|1}} * <tt><nowiki>{{Rand|1000|0}}</nowiki></tt> = {{Rand|1000|0}} * <tt><nowiki>{{Rand|1000|1|17}}</nowiki></tt> = {{Rand|1000|0|17}} (varying the prime number) * <tt><nowiki>{{Rand|1000|1|19}}</nowiki></tt> = {{Rand|1000|0|19}} * <tt><nowiki>{{Rand|1000|1|23}}</nowiki></tt> = {{Rand|1000|0|23}} * <tt><nowiki>{{Rand|1000|1|29}}</nowiki></tt> = {{Rand|1000|0|29}} * <tt><nowiki>{{Rand|1000|1|31}}</nowiki></tt> = {{Rand|1000|0|31}} * <tt><nowiki>{{Rand|1000|1|37}}</nowiki></tt> = {{Rand|1000|0|37}} * <tt><nowiki>{{Rand|1000|1|41}}</nowiki></tt> = {{Rand|1000|0|41}} * <tt><nowiki>{{Rand|1000|1|43}}</nowiki></tt> = {{Rand|1000|0|43}} * <tt><nowiki>{{Rand|1000|1|47}}</nowiki></tt> = {{Rand|1000|0|47}} * <tt><nowiki>{{Rand|1000|1|51}}</nowiki></tt> = {{Rand|1000|0|51}} * <tt><nowiki>{{Rand|1000|1|53}}</nowiki></tt> = {{Rand|1000|0|53}} * <tt><nowiki>{{Rand|1000|1|59}}</nowiki></tt> = {{Rand|1000|0|59}} * <tt><nowiki>{{Rand|1000|1|61}}</nowiki></tt> = {{Rand|1000|0|61}} * <tt><nowiki>{{Rand|1000|1|67}}</nowiki></tt> = {{Rand|1000|0|67}} * <tt><nowiki>{{Rand|1000|1|71}}</nowiki></tt> = {{Rand|1000|0|71}} * <tt><nowiki>{{Rand|1000|1|73}}</nowiki></tt> = {{Rand|1000|0|73}} * <tt><nowiki>{{Rand|1000|1|79}}</nowiki></tt> = {{Rand|1000|0|79}} ; Note<nowiki>:</nowiki> * Varying ''seed'' linearly generates numbers that generate a linear sequence on the same page, with equal cyclic steps; * Varying ''prime'' (provided that they are odd prime numbers) generates pseudo-random that have independent random distribution. * Note that when ''count'' is even (such as 100 by default, or 1000 in the examples above), the generated numbers (on the same page) are all odd or all even when you are varying the ''seed'' or ''prime'', unless half of the calls use an even ''seed'' and the others used an odd ''seed''. However, later invokations will still alternate odd and even numbers on output (this problem only occurs on the same page where multiple random numbers are invoked). * On the same page, multiple invokations of this template with the same parameters will generate the same output value, so it is possible to create multiple links related to the same article. {{attrib wikipedia|Template:Random number}}<includeonly> [[Category:Mathematical function templates]] </includeonly>
Summary:
Warning!
All contributions to Appropedia are released under the CC-BY-SA-4.0 license unless otherwise noted (see
Appropedia:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here! You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted material without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
MediaWiki:TemplateNotice.js
(
view source
)
Template:Attrib wikipedia
(
edit
)
Template:Documentation subpage
(
edit
)
Template:Mod
(
view source
) (protected)
Template:Notice
(
view source
) (protected)
Template:Notice/styles.css
(
edit
)
Template:Rand
(
edit
)
Template:Random number
(
view source
) (protected)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.
OK
Discussion