Alternative rand()-algorithm?

  • Thread starter Kristofer Berggren
  • Start date
K

Kristofer Berggren

Hi,

I'm developing a simple application which uses rand() frequently, and
I was just wondering if there are any alternatives to generating random
numbers other than the in-built function in C? I'm using GNU C/C++
compiler 3.3.1.

rand() works okay for me, but I suppose it has its limitations?

/Kristofer
 
B

Ben Pfaff

Kristofer Berggren said:
I'm developing a simple application which uses rand() frequently, and
I was just wondering if there are any alternatives to generating random
numbers other than the in-built function in C? I'm using GNU C/C++
compiler 3.3.1.

rand() works okay for me, but I suppose it has its limitations?

I have source for a portable C PRNG online at
http://benpfaff.org/writings/clc/random.html
You are welcome to use them if they solve your problem.
 
M

Malcolm

Kristofer Berggren said:
I'm developing a simple application which uses rand() frequently,
and I was just wondering if there are any alternatives to generating
random numbers other than the in-built function in C? I'm using
GNU C/C++ compiler 3.3.1.

rand() works okay for me, but I suppose it has its limitations.
There are many ways of generating random numbers. The main limitation of
rand() is that it uses a 32 bit seed, which means that a maximum of 4
billion numbers can be generated before it cycles.

This means that if, say, you are generating cards for a gambling game,
someone with access to your source code could write down the first ten or so
cards, match up the sequence, and determine the eleventh - on which maybe a
huge stake rests.

That said, the inbuilt rand() is ok for most purposes, but for a better RNG
look up "random number generator" on google. It might also be a good idea to
look in the cryptography newsgroups.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top