Template:Random number/doc: Difference between revisions

clean up some stuff (for example, "odd prime" was redundant)
(Created page with "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>...")
 
(clean up some stuff (for example, "odd prime" was redundant))
 
Line 1: Line 1:
This template generates a pseudo-random integer between 0 and ''count''-1.
This template generates a pseudo-random integer between 0 and ''count''-1.


; Usage<nowiki>:</nowiki>
=== Usage ===
* <tt><nowiki>{{</nowiki>Rand<nowiki>|</nowiki></tt>''count''<tt><nowiki>|</nowiki></tt>''seed''<tt><nowiki>|</nowiki></tt>''prime''<tt><nowiki>}}</nowiki></tt>
* <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.
* All parameters are optional and have default values. They must be integers.
Line 37: Line 37:
* <tt><nowiki>{{Rand|1000|1|79}}</nowiki></tt> = {{Rand|1000|0|79}}
* <tt><nowiki>{{Rand|1000|1|79}}</nowiki></tt> = {{Rand|1000|0|79}}


; Note<nowiki>:</nowiki>
=== Notes ===
* Varying ''seed'' linearly generates numbers that generate a linear sequence on the same page, with equal cyclic steps;
* Varying ''seed'' generates numbers in 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.
* Varying ''prime'' (provided that it is a prime number) generates pseudo-random numbers 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).
* 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.
* 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.
6,906

edits