Difference between revisions of "Template:RNG"

From RimWorld Wiki
Jump to navigation Jump to search
(Still a WIP, needs documentation.)
 
(Making types.)
Line 2: Line 2:
 
{{impressive}}
 
{{impressive}}
 
Generic random number:<onlyinclude>
 
Generic random number:<onlyinclude>
{{#switch:{{{type|}}}
+
{{#switch:{{{1|}}}
|#default = {{#expr:(({{{seed|}}}+0)*37+{{CURRENTTIMESTAMP}}-{{REVISIONTIMESTAMP}})*97 mod {{#if:{{{limit|}}}|{{{limit}}}|100}}}}
+
|#default = {{#expr:(({{{seed|}}}+0)*371+{{CURRENTTIMESTAMP}}-{{REVISIONTIMESTAMP}})*325 mod {{#if:{{{limit|}}}|{{{limit}}}|100}}}}
|case 2 = {{#expr:{{REVISIONTIMESTAMP}}*97+({{{seed|}}}+0) mod {{#if:{{{limit|}}}|{{#expr:1+{{{limit}}}}}|100}}}}
+
|case 2 = {{#expr:{{REVISIONTIMESTAMP}}*113+({{{seed|}}}+0) mod {{#if:{{{limit|}}}|{{#expr:1+{{{limit}}}}}|100}}}}
|case 3 = {{#expr:{{CURRENTTIMESTAMP}}*97+({{{seed|}}}+0) mod {{#if:{{{limit|}}}|{{#expr:1+{{{limit}}}}}|100}}}}
+
|case 3 = {{#expr:{{CURRENTTIMESTAMP}}*85+({{{seed|}}}+0) mod {{#if:{{{limit|}}}|{{#expr:1+{{{limit}}}}}|100}}}}
 
}}
 
}}
 
</onlyinclude>
 
</onlyinclude>
Line 12: Line 12:
 
<b>Generated numbers:</b>
 
<b>Generated numbers:</b>
  
Type 1 seed 1:{{RNG |type=1|seed=1}}<br />
+
Type 1 seed 1:{{RNG |1|seed=1}}<br />
Type 2 seed 1:{{RNG |type=2|seed=1}}<br />
+
Type 2 seed 1:{{RNG |2|seed=1}}<br />
Type 3 seed 1:{{RNG |type=3|seed=1}}
+
Type 3 seed 1:{{RNG |3|seed=1}}
 
</div>
 
</div>
  
 
{{{{BASEPAGENAME}}/doc}}
 
{{{{BASEPAGENAME}}/doc}}

Revision as of 07:25, 12 December 2016

Generic random number: 25

Generated numbers:

Type 1 seed 1: 0
Type 2 seed 1: 0
Type 3 seed 1: 0

Description

This template is used to generate random numbers in a relatively short time.

Usage

Type {{RNG}} on the page to assume a seed of 0 and a limit of 100.

NOTE: Setting a limit value to something greater than 1 000 000 WILL have an effect on the randomness of the result. Use two {{RNG}} templates instead.
{{RNG
|seed=(number)            -->Makes RNGs with different seeds unique to each other.
|limit=(number)           -->Restricts the RNG to produce only numbers from 1 to limit.
}}

Example:

{{RNG
|seed=1234
|limit=5000}}

results in: 875