Jump to content

Recommended Posts

Posted (edited)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

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.