I am using rand() function, but it always uses the same random sequence. Is there a random function that seeds with the clock value? And how would I do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are meant to seed
rand()andrandom()(slightly bigger space) yourself, with their respective seed functions, before using them. You can use the time, or whatever other value you desire:Here we get the system time; obviously passing a constant will produce the same sequence every run.
You can also use
arc4random()which generates very high-quality random bits and seeds itself using /dev/random.