User Tools

Site Tools


cw4:4rpl_tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cw4:4rpl_tools [2025/08/18 16:46] – [Next UseFul Function goes here] kallicw4:4rpl_tools [2025/08/29 21:04] (current) – [Pseudo RNG based on Linear congruential generator (LCG)] kalli
Line 3981: Line 3981:
 ===== Pseudo RNG based on Linear congruential generator (LCG) ===== ===== Pseudo RNG based on Linear congruential generator (LCG) =====
  
-The downside of the above sinus based functions, is that they have few resulting digits. They are more than adequate to pick a random cell on a map (max 512 possibilities), but unsuited for generating random numbers larger than a few thousand. The below LCG functions should work for up to 6 digits = 10^6, but I've only done a test up to 10^5. +The downside of the above sinus based functions, is that they have few resulting digits. They are more than adequate to pick a random cell on a map (max 512 possibilities), but unsuited for generating random numbers larger than a few thousand.  
 + 
 +The below LCG functions should work for up to 6 digits = 10^6, but I've only done a test up to 10^5. Rolling 1 million random integers between 0 and 10^5 with @lcgRandInt, missed only 8 possible results. The same test with @sinRandInt missed 42458 possible results.
  
 <hidden click here for source code> <hidden click here for source code>
Line 4019: Line 4021:
 ->last ->last
 ->first ->first
- elapsedtime dup 10 log ceil 7 sub neg 10 swap pow mul <-first <-last @seededLcgRandInt+ elapsedtime dup 10 log ceil 7 sub neg 10 swap pow mul asint <-spikedLcgAdd 1 add dup ->spikedLcgAdd mul @seededLcgRand01 <-last <-first sub mul <-first add asint
   
 :spikedLcgRand01 :spikedLcgRand01
- elapsedtime dup 10 log ceil 7 sub neg 10 swap pow mul @seededLcgRand01+ elapsedtime dup 10 log ceil 7 sub neg 10 swap pow mul asint <-spikedLcgAdd 1 add dup ->spikedLcgAdd mul @seededLcgRand01
  
 :seededLcgRandInt # INPUT: integer seed + integer first randInt + integer last randInt. OUTPUT: an integer in between the first and last randInt, excluding the last randInt. :seededLcgRandInt # INPUT: integer seed + integer first randInt + integer last randInt. OUTPUT: an integer in between the first and last randInt, excluding the last randInt.
cw4/4rpl_tools.1755535589.txt.gz · Last modified: 2025/08/18 16:46 by kalli