Page 1 of 1

random number generator powered by lava lamp

PostPosted:Wed Feb 02, 2005 8:49 pm
by Nev
http://www.lavarnd.org/news/lavadiff.html

read the left hand side if interested, i thought this was neat

PostPosted:Wed Feb 02, 2005 8:52 pm
by Nev
maybe i should have linked the main site...

the original lavarnd was a random number generator that used a unique source of entropy - a lava lamp - as its random number generator. it's really interesting i think that computers have such a hard time with randomness...

PostPosted:Wed Feb 02, 2005 10:40 pm
by Kupek
You can get just as good randomness through, say, the soundcard or other devices. But you rarely need true randomness - in fact, it's often better to use a pseudo-random number generator because then behavior is reproducable. This algorithm will serve most needs (change the seed to get diferent "streams"):
Code: Select all
double randomNumber() {

  static long int seed = 547845897;
  static long int m = 2147483647; // m is the modulus, m = 2 ^ 31 - 1
  static long int a = 16807;              // a is the multiplier, a = 7 ^ 5
  static long int q = 127773;             // q is the floor of m / a
  static long int r = 2836;               // r is m mod a

  long int temp;
  temp = a * (seed % q) - r * (seed / q);

  if (temp > 0) {
    seed = temp;
  }

  else {
    seed = temp + m;
  }

  return (double)seed / (double)m;
}

PostPosted:Thu Feb 03, 2005 12:37 pm
by Nev
why would you want reproducible behavior if you need a random number? that's sort of a contradiction in terms isn't it?

PostPosted:Thu Feb 03, 2005 1:41 pm
by Kupek
Mental wrote:why would you want reproducible behavior if you need a random number? that's sort of a contradiction in terms isn't it?
If you don't know how they're used, then I can see how it would appear so. Most of my experience with random number generators is from simulations. The simulations we wrote were discrete event simulations; we used some know distribution to model some phenomenon, say, the arrival time of people to a lunch line. Getting a number from some known distribution requires generating a "random" number and applying the appropriate function to that number.

Now, let's say you're running your simulation, and some wierd behavior comes up - you will want to investigate this behavior further. And doing that requires being able to reproduce that behavior. If you're using truly random numbers, then you won't be able reproduce it, but if you're using pseudo-random numbers from a known number generator, you can.

All pseudo-random number generators will eventually cycle around and start repeating, but if the numbers used are large enough (like in the snippet of code I put up), it won't matter. The amount of numbers you'll go through before repeating is on the order of 2^32. Even simple algorithms like that one produce number streams that are, in most cases, indistinguisable from true random numbers.

There are, of course, areas in which you might want true random numbers, such as cryptography, but even then, I wouldn't be surprised if they're using pseudo-random numbers instead. On a computer, getting a truly random number requires interacting with some hardware - the Linux kernel uses the keyboard somehow - which is much, much slower than the above function.

PostPosted:Thu Feb 03, 2005 2:00 pm
by Nev
i guess there's not that much use for it yet. there will be, though.

randomness is interesting...i think you can see a lot of things that are supposed to be "random" and really aren't...

PostPosted:Fri Feb 04, 2005 2:50 am
by SineSwiper
Image

PostPosted:Fri Feb 04, 2005 3:38 am
by Nev
rotflmao!

well, not really, but you get the idea. :)