被永久保护的模板

Template:Rand

维基百科,自由的百科全书
跳到导航 跳到搜索
文档图示 模板文档[查看] [编辑] [历史] [清除缓存]

这个模板会在数0与|count|-1之间生成一个伪随机整数。

Usage:
  • {{Rand|count|seed|prime}}
  • 所有参数都是可选的并且有默认值。参数必须是整数值。
  • count 的默认值是100(所以在默认情况下,这个模板会生成一个范围包含两端,介于0至99之间的值),count 不能设定为0。正整数和负整数都是可行的。
  • seed 的默认值是{{#time:z}},(seed的默认值现在是313),也可以设成任何其它整数值。(这样就能在同一页生成不同的值)。
  • prime 的默认值是89,若需要设置特定的值,则必须是17或以上的质数。(这样就能在同一页生成不同的值)。
Examples generating numbers between 0 and 999:
  • {{Rand|1000}} = 371
  • {{Rand|1000|313|89}} = 371(与上行结果相同)
  • {{Rand|1000|313|61}} = 407 (此行与余下多行结果不同)
  • {{Rand|1000|6}} = 888
  • {{Rand|1000|5}} = 919
  • {{Rand|1000|4}} = 950
  • {{Rand|1000|3}} = 981
  • {{Rand|1000|2}} = 12
  • {{Rand|1000|1}} = 43
  • {{Rand|1000|0}} = 74
  • {{Rand|1000|1|17}} = 762(此行开始,更改 prime 参数的值)
  • {{Rand|1000|1|19}} = 814
  • {{Rand|1000|1|23}} = 302
  • {{Rand|1000|1|29}} = 394
  • {{Rand|1000|1|31}} = 94
  • {{Rand|1000|1|37}} = 842
  • {{Rand|1000|1|41}} = 314
  • {{Rand|1000|1|43}} = 22
  • {{Rand|1000|1|47}} = 182
  • {{Rand|1000|1|51}} = 734
  • {{Rand|1000|1|53}} = 682
  • {{Rand|1000|1|59}} = 334
  • {{Rand|1000|1|61}} = 354
  • {{Rand|1000|1|67}} = 462
  • {{Rand|1000|1|71}} = 174
  • {{Rand|1000|1|73}} = 602
  • {{Rand|1000|1|79}} = 294
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}},类似的模板。