+ 5

srand and rand

I know that srand generates truly random numbers and rand doesn’t, so why does rand even exist? Does it run faster than srand?

28th Dec 2017, 12:51 AM
Jacob Pembleton
Jacob Pembleton - avatar
1 Respuesta
+ 10
You're not entirely correct there. srand sets the seed . random numbers are not truly random they are based off of a seed number. if you place the same value in srand each time you will continually pull numbers from the same set. Which is why we use srand usually with the OS time to get a unique number for our seed. Random is the function that actually generates the numbers based off of that seed.
28th Dec 2017, 1:21 AM
Michael Simnitt
Michael Simnitt - avatar