In cryptography or science in general, you often need perfect random numbers. Well, up to today, that was my need as well. However, today I was trying to generate numbers that are not too random, but have a certain bias. I think it’s kind of ironic. Googling for a solution is almost impossible. Every link shows a perfect random number generator 😉
I don’t care what the bias is in the numbers that are generated. Actually, the bias can be pretty high. Anyone have a method to do this in Perl?
Can you do something like int(rand($upperLimit*1000)) % 1000 ??? Basically changing the interval from where the random number is taken and then shrinking it again?
I guess I am going to answer my own question. I believe this is doing the trick:
int(rand($upperLimit)^2)]
You square your random number and you generate a bias towards 1. If you cube, the bias will be worse, etc. Yes?
Comment by Raffy — March 20, 2007 @ 9:31 pm
Wow, my Perl skills are certainly not the best. The idea was right, but here goes the correct way:
int((rand()**2)*$upperLimit)
Comment by Raffy — March 20, 2007 @ 9:42 pm
What, you want to take a flat line between 0 and 1, and slant the right a up bit? Take a random number and add a second random number divided by 10 or 100.
Comment by Ryan Russell — March 23, 2007 @ 11:19 pm
Oh, wait. I’m trying to reinvent the formula for slope. Yeah, just multiple by 1.1, square it, etc…
Comment by Ryan Russell — March 23, 2007 @ 11:21 pm
It depends how much selectivity you want over the bias. I believe if you want total selectivity over the bias in the frequency domain you will have to apply an inverse FFT to a good, linear congruential generator.
It would probably be a good idea to read about white and pink noise distributions.
Comment by eris — September 21, 2011 @ 12:33 pm