0
Why is my code not generating random numbers?
https://code.sololearn.com/c7IFyEGmKF2i/?ref=app When i simply use the rand( ) and srand( ) functions in main( ) function, the program runs just fine. But, when i create a new function by the name of Switch ( ) that has the same functionality, the program doesnt generate random numbers. What is wrong here? Thanks!!
2 Réponses
+ 5
Because you re-seed the RNG with srand() each time you call Switch(). Remove line 22. Seeding the RNG once in your main is enough.
0
Thanks alot Hatsy Rei . Could you also explain how to create a Display( ) function that behaves like a printf. I tried creating the function with if else statements. But the problem i am facing is in returing the output as it is in the form of a string, "RED" or "GREEN" and you cannot return strings in a function.