Active 3 years, 3 months ago. Viewed 64k times. Improve this question. Matthew 4 4 silver badges 16 16 bronze badges. Sunrise Sunrise 1, 3 3 gold badges 14 14 silver badges 28 28 bronze badges. It depends on what you are doing. It is just s pseudo-random generator, after all. It's a very crappy one, and it's not possible to prove any properties about the distribution which is probably important if you're generating random numbers in the first place.
Add a comment. Active Oldest Votes. Video explaining why: rand Considered Harmful rand is typically a low quality pRNG and not suitable for applications that need a reasonable level of unpredictability.
Improve this answer. All things are relative, and depending on what you are doing, rand may be largely sufficient. Also, why all these presentations as videos?
JamesKanze Headphones are handy in an office. There are probably also decent text resources but I don't know of any off hand. And you're incorrect that no one considers rand harmful. JamesKanze "there was nothing in it I wasn't already thoroughly aware of" And there was nothing in it I wasn't aware of either. I guess once one person knows something we should burn all copies of that information and never mention it?
Programmers, managers, etc. Part of that is showing how it's better. I also think 'exceptional' is an underestimate of its availability. Getting the same level of abstraction out of rand means implementing it oneself. Show 8 more comments. Atlant Atlant 61 1 1 silver badge 1 1 bronze badge. When available, random does not suffer of this issue. AnT AnT k 39 39 gold badges silver badges bronze badges.
We will also provide a seed value in an unsigned integer. We will make seed value the return value of the time 0 function which will be different every execution of the application. We can see that every time we call the random function we get a different value which is completely random. But start number will be. Nice article. With the help of this article, I understood the concept of rand in the c programming language.
Any other value for seed sets the generator to a different starting point. Syntax: void srand unsigned seed : Seeds the pseudo-random number generator used by rand with the value seed. Note: The pseudo-random number generator should only be seeded once, before any calls to rand , and the start of the program. It should not be repeatedly seeded, or reseeded every time you wish to generate a new batch of pseudo-random numbers.
Standard practice is to use the result of a call to srand time 0 as the seed. Output 1: 89 Output 2: 45 Output n: How srand and rand are related to each other?
In short, srand — Set Seed for rand Function. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Skip to content. Change Language.
0コメント