[ create a new paste ] login | about

Link: http://codepad.org/zfAyc24z    [ raw code | output | fork ]

C, pasted on Apr 12:
/* rand example: guess the number */
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

int main ()
{
  int r, i;
  int N = 1,
      M = 12;
      //RAND_MAX = 12;
  /* initialize random seed: */
  srand (time(NULL));

  /* generate secret number between 1 and 10: */
  for(i=0; i < 10 ; i++){ 
     r = M + rand() / (RAND_MAX / (N - M + 1) + 1);
     printf("%d\n", r);
  }


  puts ("Congratulations!");
  return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
9
4
7
12
11
4
10
7
9
8
Congratulations!


Create a new paste based on this one


Comments: