diff options
author | Jesusalva Jesusalva <jesusalva@themanaworld.org> | 2023-07-17 01:48:55 +0000 |
---|---|---|
committer | Jesusalva Jesusalva <jesusalva@themanaworld.org> | 2023-07-17 01:48:55 +0000 |
commit | cc560ebdfdd5368a4d944003871a8f7f3a77bf57 (patch) | |
tree | 5a82418c9f0b725fed8d5e5cf0c1fa1a6fe861bc /npc/functions/main.txt | |
parent | cac5c770e7bbb169e9516909dfc0d44afceb1446 (diff) | |
parent | 5b0a9c8ffdbac30c4ff3981167c7206ca75425c7 (diff) | |
download | serverdata-cc560ebdfdd5368a4d944003871a8f7f3a77bf57.tar.gz serverdata-cc560ebdfdd5368a4d944003871a8f7f3a77bf57.tar.bz2 serverdata-cc560ebdfdd5368a4d944003871a8f7f3a77bf57.tar.xz serverdata-cc560ebdfdd5368a4d944003871a8f7f3a77bf57.zip |
Merge branch 'jesusalva/00610' into 'master'
Jesusalva/00610
See merge request CR/serverdata!1
Diffstat (limited to 'npc/functions/main.txt')
-rw-r--r-- | npc/functions/main.txt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/npc/functions/main.txt b/npc/functions/main.txt index b2a7a78..999d18c 100644 --- a/npc/functions/main.txt +++ b/npc/functions/main.txt @@ -299,6 +299,34 @@ function script any_of { return getelementofarray(getarg(0), getarrayindex(getarg(0)) + rand2(getarraysize(getarg(0)) - getarrayindex(getarg(0)))); } +// Miller Algorithm implementation for shuffling (PRIG) +// miller_rand( state, seed, array_size ) +function script miller_rand { + .@inx = getarg(0); + .@shuffleID = getarg(1); + .@listSize = getarg(2); + + .@shuffleID += 131 * (.@inx/.@listSize); // have inx overflow effect the mix + .@si = (.@inx + .@shuffleID) % .@listSize; // cut the deck + + .@topEven = .@listSize - (.@listSize & 1); // compute reference value + .@r1 = .@shuffleID % 0xFFF; // improved randomizing values + .@r2 = .@shuffleID % 0x3FFF ^ .@r1; + .@r3 = .@shuffleID / 881 + 3; + .@rx = (.@shuffleID / .@listSize) % .@listSize + 1; + + // NOTE: the next line operates only 1/3 the time, the following line 1/2 + if (.@si % 3 == 0) + .@si = (((.@si/3)*3343+.@r1) % ((.@listSize+2)/3)) * 3; // spin multiples of 3 + if (.@si&1) + .@si = (2 * .@r2 + .@topEven - .@si) % .@topEven; // reverse+rotate flow of odd #s + if ((.@si ^ .@rx) < .@listSize) + .@si ^= .@rx; // flip some bits with Xor + .@si = (.@si * 9973 + .@r3) % .@listSize; // turn more prime wheels + + return .@si; +} + function script die { if ($HARDCORE) { @grace=true; |