This content has been marked as final.
Show 3 replies

1. Re: Generate random numbers following geometric distribution
800282 Jun 12, 2007 2:31 PM (in response to 807605)int n = rand.nextInt(100); // n = number in the range [0,99>

2. Re: Generate random numbers following geometric distribution
807605 Jun 12, 2007 2:47 PM (in response to 807605)I use this code to generate random geometric numbers.
Well, would they comply with the geometic distribution if they did?
The problem is that the resulting numbers don't fit
into a certain range. 
3. Re: Generate random numbers following geometric distribution
807605 Jun 12, 2007 7:12 PM (in response to 807605)When one looks up "geometric distribution" on Wikipedia one finds something like this:
..."For example, suppose an ordinary die is thrown repeatedly until the first time a "1" appears. The probability distribution of the number of times it is thrown is supported on the infinite set { 1, 2, 3, ... } and is a geometric distribution with p = 1/6."...
The telling thing is the comment "supported on an infinite set" Sometimes you get the one in one roll and sometimes (not very likely) it takes a million.
You can easily simulate a Bernouli process by just rolling the dice (using the uniform random number generator) and counting how long it takes you to hit the desired number (or range of numbers  for example you would simulate probability 2/3 by rnd.nextInt(3)<2 ). This returns numbers distributed geometrically one at a time, BUT the support set is infinite. What do you mean scaled between 1 and 100? You don't scale infinite sets, and if you chop it off at some point it isn't really geometric now is it?
Chopping it off is easy. Simply stop counting and stop simulating dice rolls, when you hit the max count that you want to get back.
And of course you don't need to do a discrete simulation, you can do what you did, using uniformly distributed doubles and log caclulations. BUT the resutt set is infinite as it should be. You can do the same thing there, just mash the infinite tail into the last number, or toss it out completly and generate a new number. In any case, you are introducing an error from a true infinite geometric distribution and replacing it with something that resembles a geometric distribution and you can distribute the error (the places where you decided to cheat) through out the distribution however you like.
So do whatever you must to achieve the effect that you want but what you say you want to do, to scale a geometric distribution, does not actually make any sense.