The Other Worlds Shrine

Your place for discussion about RPGs, gaming, music, movies, anime, computers, sports, and any other stuff we care to talk about... 

  • random number generator powered by lava lamp

  • Somehow, we still tolerate each other. Eventually this will be the only forum left.
Somehow, we still tolerate each other. Eventually this will be the only forum left.

 #82743  by Nev
 Wed Feb 02, 2005 8:52 pm
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...

 #82751  by Kupek
 Wed Feb 02, 2005 10:40 pm
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;
}

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

 #82790  by Kupek
 Thu Feb 03, 2005 1:41 pm
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.

 #82796  by Nev
 Thu Feb 03, 2005 2:00 pm
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...

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

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

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