|
Random Number Generation |
|
rand function |
|
#include <stdlib.h> |
|
(1) Scaling |
|
Shifted, scaled integers produced by 1 + rand() % 6
#include <stdio.h> |
|
(2) Randomize |
|
|
srand function |
include<stdlib.h>
The random number generator is reinitialized by calling srand with an argument value of 1. It can be set to a new starting point by calling srand with a given seed number.
srand( seed );
srand( time( NULL ) ); //load <time.h>
time( NULL )
|
Randomizing ways |
|||
randomize(): Initializes random number generator |
srand( seed ); |
srand( time(NULL) ); |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
Roll a six-sided die 6000 times |
|
#include <stdio.h> |
|
Craps simulator Rules:
|
|
|