Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

rand() c++

Options
  • 17-04-2008 9:38pm
    #1
    Registered Users Posts: 960 ✭✭✭


    Hi, sorry if this has come up before I ran a search and couldn't find anything. I'm very new to programming.

    Basically I'm learning how to use rand() but I've encountered a problem, I can run it fine and get a set or random(well pseudo but thats ok) numbers but I can't find a way to use these numbers again, if i try put them in an array or put them equal to an integer if i try use this i just get a set of different numbers


Comments

  • Registered Users Posts: 4,287 ✭✭✭NotMe


    Every time you call rand() you get a different number. It sounds like you're calling rand() / assigning it to a variable inside a loop so that every iteration the value changes.


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    yeh you'd need something like this
    array[10]
    for int i:=0 to i=10
    begin
           array[i] := rand()
    end
    
    that will assign each element of array a pseudo random number.


Advertisement