Jump to content

my little rng

Featured Replies

so lately I've been studying randomness for no particular reason.

the problem with most prng is they use both multiplication and modulus, both expensive, and are not necessarily very good at producing randomness.

i believe i've come up with a nice, compact pseudo-random number generator. here it is in python.

v = [0]*3
seed1 = 1995714531
v[0] = 0x96696996
v[1] = seed1
v[2] = 0xb5b5adad
def rot(x,k):
  return ((x<<k)|(x>>(32-k)))&4294967295
  #the &num is unnecessary in other programing languages

def rng():
  v[0], v[2], v[1] = rot(v[2],8), rot(v[1],17), v[0]^(~v[1]&v[2])
  return v[1]

Edited by phillip1882

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.