Perl-Sensitive Sunglasses PerlMonks

### Re^2: generate random number without using any built in function in perl?

by Laurent_R (Canon)
 on May 08, 2013 at 22:08 UTC ( #1032688=note: print w/replies, xml ) Need Help??

Not to be obtuse, but why can't you use rand? This smacks of an XY Problem.

Yes, I fully agree.

To the OP: please tell us why you can't (or don't want to) use the Perl random number generator, which is, I think, of a high quality and has been well tested over many years, and would want to go for something else, which is likely to work much less properly unless you are willing to commit huge amount of time to test how well it performs.

I once made a very basic pseudo random number generator, because I did not have any library available to do that for me in the environment that I was using. It ended up working for the purpose that I had, because the requirement was really not demanding. But trying to do that, you figure out that this is a very difficult problem, and sometimes very clever ideas fail miserably. (I knew it was quite difficult before I started, but I did not realize how much more difficult than I thought it was.)

I would suggest that you take a look at Donald Knuth's "The Art of of Computer Programming", Volume 2, Seminumerical Algorithms, Chapter 3, Random Numbers. Once you've read through the 190 pages (in the edition that I own) devoted to random numbers, I think that you will agree that you probably don't want a "quick fix" solution to such a complicated problem. Using a well tested library is far safer in probably more than 99.99% of the cases.

• Comment on Re^2: generate random number without using any built in function in perl?

Create A New User
Node Status?
node history
Node Type: note [id://1032688]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-05-26 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (192 votes). Check out past polls.

Notices?