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]

Comments

  • : 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]

    If you have a vector then use its begin() and end() methods as the first two arguments
    [code]
    vector array;
    array.resize(20);
    random_shuffle(array.begin(), array.end(), rand);
    [/code]

    If you have a standard C style array
    [code]
    int array[20];
    random_shuffle(array, array+20, rand);
    [/code]



    Conversation should be pleasant without scurrility, witty without affectation, free without indecency, learned without conceitedness, novel without falsehood.
    William Shakespeare
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!

Categories

In this Discussion