Generating Random numbers

i'm having trouble finding a function that randomizes an array or generates a random number in C++. Please help!!

all i know at the moment is the random_shuffle function...

#include // header used for shuffle
random_shuffle(start, end, pointer_to_unary_function(Rand));

...but i still don't know exactly how to use it. I just need some pointers on generating random numbers. Thanks in advance.
[size=3]"I am a [/size]Slave,[size=2] and a[/size] [size=4][red]Master[/red][/size][size=2]"-[italic]Slipknot[/italic][/size]


  • [blue]
    Check out these functions:

    srand() - initializes a new sequence of random numbers
    rand() - generates a random number from 0 to RAND_MAX

    To get a random number in any range, use the MOD operation to get a remainder of the random number:
    int nFrom0To9 = rand() % 10; // generates in range [0..9]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion