模板:Rand/doc
外觀
![]() | 此頁面是Template:Rand的模板文件。 此頁面可能包含了模板的使用說明、分類和其他內容。 |
![]() | 此模板的文檔不存在、不全面或不能詳細描述其功能及/或其代碼中的參數。請幫助擴充並改進其文檔。 |
這個模板會在數0與|count|-1之間生成一個偽隨機整數。
- Usage:
{{Rand|
count|
seed|
prime}}
- 所有參數都是可選的並且有默認值。參數必須是整數值。
- count 的默認值是100(所以在默認情況下,這個模板會生成一個範圍包含兩端,介於0至99之間的值),count 不能設定為0。正整數和負整數都是可行的。
- seed 的默認值是{{#time:z}},(seed的默認值現在是228),也可以設成任何其它整數值。(這樣就能在同一頁生成不同的值)。
- prime 的默認值是89,若需要設置特定的值,則必須是17或以上的質數。這樣就能在同一頁生成不同的值)。
- Examples generating numbers between 0 and 999:
{{Rand|1000}}
= 628{{Rand|1000|228|89}}
= 628(與上行結果相同){{Rand|1000|228|61}}
= 4 (此行與餘下多行結果不同){{Rand|1000|6}}
= 510{{Rand|1000|5}}
= 541{{Rand|1000|4}}
= 572{{Rand|1000|3}}
= 603{{Rand|1000|2}}
= 634{{Rand|1000|1}}
= 665{{Rand|1000|0}}
= 696{{Rand|1000|1|17}}
= 448(此行開始,更改 prime 參數的值){{Rand|1000|1|19}}
= 276{{Rand|1000|1|23}}
= 180{{Rand|1000|1|29}}
= 936{{Rand|1000|1|31}}
= 436{{Rand|1000|1|37}}
= 408{{Rand|1000|1|41}}
= 136{{Rand|1000|1|43}}
= 180{{Rand|1000|1|47}}
= 388{{Rand|1000|1|51}}
= 436{{Rand|1000|1|53}}
= 280{{Rand|1000|1|59}}
= 716{{Rand|1000|1|61}}
= 336{{Rand|1000|1|67}}
= 348{{Rand|1000|1|71}}
= 836{{Rand|1000|1|73}}
= 680{{Rand|1000|1|79}}
= 236
- Note:
- 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 ouput value, so it is possible to create multiple links related to the same article.
參見
[編輯]- {{rand2}},類似的模板。