C++

Can anyone suggest me how to generate a random number on C++ visual studio?
Last edited on
*My friend and I are lazy and want you to do our homework.
That's what it should say.

EDIT: That's more like the question we like to see. I'm sorry for being rude, but no one likes it when you copy-paste your homework assignment onto this site and expect us to do it for you.
To generate random numbers use the
rand()
function, but note that you have to seed it using
srand()
before you can use it.
A full set up would look like this:
1
2
3
4
#include <time.h> //Include this for the "time()" function used for seeding

srand(time(0));
int random = rand();

Not that this will generate a number from 0 - 1. To get a different range use the "%" operator:
 
int random = rand()%100 //This will generate a number from 0-99 
Last edited on
To be less rude than the poster above, What problems do you have with the program. Post what you cant seem to get working, we'll help you with that, but we dont write it for you.
Topic archived. No new replies allowed.