0
What's the difference between rand() and srand()?
I want to know diff between random and truly random no
12 Respostas
+ 5
we usually give it the time. that way srand always has a unique value
+ 4
watch video on how to do it and follow along in codeplayground. it will make it alot easier to understand if you see it in action
+ 4
oooooo i understand now.. if we use the same seed rand will give the same results
+ 4
computers can not give true random numbers on their own if that is what you are asking
+ 3
they are used together. srand is used to give rand a seed value.
Have you ever played minecraft? If so do you know about world seeds? and how if you enter one the world that is generated is always the same whenever you reenter that seed? that is what srand is used for.
we generate random numbers by giving srand a unique seed value. Usually by using the current time. so when we use rand the numbers it produces are always unique (as it is never the same date and time)
so for example
srand(9); \\ when using 9 as seed rand will always produce the same set of random numbers
srand(time(0)); \\ when using time as a seed rand will produce a different set or random numbers
hope this helps
+ 3
srand is used with rand. without it rand will always give the same numbers. they will be random but they will be the same everytime the program is run. by using srand with rand we give the computer something to use to help randomise with.
you will never get truly random numbers from rand. but they are good enough for many purposes.
0
pls explain seed and truly random no meaning
0
does that mean we give a random no from our side!
0
no I wanted to ask whether the seed value creates a truly random value or it just pretends to be by taking our input
0
thanks buddy
0
then srand() is just like following a bit diff path to reach same result!!!