The Open Source Swiss Army Knife

/code/cPP/basics_cPP/
/code/cPP/basics_cPP/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /cPP   /basics_cPP 
Permalink: srand.c
Title: add
article options : please login   |  raw source view  

#include <iostream.h>
#include <stdlib.h>
#include <time.h>

int main() {
	int i;
	time_t t;

	// seed the random

	srand((unsigned)time (&t));
	// srand sets a random seed
	// equivalent to srand( time (0) );
	cout << "ten random numbers from 0 to 99:\n\n";
	for (i = 0; i < 10; i++) {
		cout << rand() % 100 << endl;
	}
	return 0;
}
//  cout << rand() % 6 + 1 << endl;
// goes from 1 -> 6
// without the " + 1 " goes from 0 to 5

// the number after the modulus is the number of choices we want to return


Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top