how to create a random number generator function till range of unsigned int

how to create a random number generator function till range of unsigned int
rand() already does that.

Or, you could make your own linear congruentlial RNG if you know how to choose a and b
(look it up on google or wikipedia).

Or there are many other RNGs out there as well.

EDIT: though 32-bit LCRNGs are not good for generating RNGs in their full range because a 32-bit LCRNG with an appropriate a and b have the distinct non-random property that every integer [ 0... 2^32 - 1] occurs exactly once before the pattern repeats.

If you need RNGs in the full 32-bit range then you'll need an RNG with a cycle much larger than 2^32 (google ISAAC random number generator).
Last edited on
hiii thanks for ur reply
but i did'nt get ur point plz explain me if u can
if u can plz send me some code for this that will be helpful for me plzz
rand()%(#)
replace # with a number signifying the highest number you want to be randomly generated.

i.e.

y=rand()%(10)
assigns a random number between 0-10 to variable y

y=1+rand()%(10)
assigns a random number between 1-10 to variable y

dont forget to seed rand()

Needs <ctime>
srand((unsigned)time(0))
Topic archived. No new replies allowed.