How to generate random numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to generate random numbers

How to generate random numbers between 1 to 100 in C Without using srand()

19th May 2021, 3:02 AM
Ankush Gauro
2 Answers
+ 4
You can use rand() without first calling srand() [the seed function]. It just produces the same sequence every time you run your program. --------- If you also wish to avoid using rand(), you can implement a pseudo-random routine of your own. Here is an example, although it is not certified for randomness: https://code.sololearn.com/c5Cgo15HcF98/?ref=app --------- To reduce its range to 1 to 100, take the random result and use modulo 100 and add 1.
19th May 2021, 3:39 AM
Brian
Brian - avatar
+ 4
If you have access to google.com, try searching for this: "random number generator". relevant link: https://stackoverflow.com/questions/7602919/how-do-i-generate-random-numbers-without-rand-function
19th May 2021, 3:42 AM
NEZ
NEZ - avatar