How do I generate random numbers in C? The user doesn't enter anything, I'm just looking for a way to generate random numbers every time I run the program.

Thanks guys!

Recommended Answers

All 5 Replies

How do I generate random numbers in C? The user doesn't enter anything, I'm just looking for a way to generate random numbers every time I run the program.

Thanks guys!

I would lookup random or srandom...for pseudo random functions in C

You could use rand() or srand() for it. Read the manual in google for the details.

How do I generate random numbers in C? The user doesn't enter anything, I'm just looking for a way to generate random numbers every time I run the program.

Thanks guys!

"srand()/rand()" isn't exactly the most sophisticated random number generator in the world, but it *should* work for your purposes.

>I would lookup random or srandom...for pseudo random functions in C
Neither of which are standard functions, meaning unless the OP has the same compiler you do, the chances of your suggestion working are somewhat slim. srand and rand are the standard functions for seeding and generating random numbers.

You can try seeding the random number generator with a call to time().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.