Advertisement
thenewboston

C Programming Tutorial - 38 - Random Number Generator...

Aug 22nd, 2014
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6.  
  7. int main()
  8. {
  9.     int i;
  10.     int diceRoll;
  11.  
  12.     for(i=0; i<20; i++){
  13.         //returns a random integer from 0 to 32767
  14.         printf("%d \n", rand() );
  15.         //returns a number 1-6
  16.         diceRoll = ( rand()%6 ) + 1;
  17.         printf("You rolled a %d \n", diceRoll );
  18.     }
  19.  
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement