Pseudo Random Number Generators PRN Mix of some simple random number generators Have a wide range of applications beyond encriptions fo examples when generating textures adding test noise or creating reproducable patterns seed regenerate numbers that have deterministic nature Applications noise hashes predictable random var seed 1 function random var t seed 0x6D2B79F5 t Math imul t t 15 t 1 t t Math imul t t 7 t 61 return t t 14 0 4294967296 for let i 0 i 10 i console log random var seed 1 function random var x Math sin seed 10000 return x Math floor x for let i 0 i 10 i console log random var mask m_w m_z function seed s mask 0xffffffff m_w 123456789 s mask m_z 987654321 s mask function random m_z 36969 m_z 65535 m_z 16 mask m_w 18000 m_w 65535 m_w 16 mask var result m_z 16 m_w 65535 0 result 4294967296 return result seed 1 for let i 0 i 10 i console log random function sfc32 a b c d return function a 0 b 0 c 0 d 0 var t a b 0 a b b 9 b c c 3 0 c c 21 c 11 d d 1 0 t t d 0 c c t 0 return t 0 4294967296 set random starting seed var seed 9999 Output four 32 bit hashes to provide the seed for sfc32 var random sfc32 seed seed seed seed for let i 0 i 10 i console log random
m_z 987654321 s mask function random m_z 36969 m_z 65535 m_z 16 mask m_w 18000 m_w 65535 m_w 16 mask var result m_z 16 m_w 65535 0 result 4294967296 return result seed 1 for let i 0 i 10 i console log random function sfc32 a b c d return function a 0 b 0 c 0 d 0 var t a b 0 a b b 9 b c c 3 0 c c 21 c 11 d d 1 0 t t d 0 c c t 0 return t 0 4294967296 set random starting seed var seed 9999 Output four 32 bit hashes to provide the seed for sfc32 var random sfc32 seed seed seed seed for let i 0 i 10 i console log random