Advertisement
Guest User

MyRand

a guest
Feb 10th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. int myRand(int min, int max){
  2.   int result = 0 , low = 0 ,hig = 0;
  3.   static int oneTime = 0;   // Srand patch
  4.  
  5.   if ( min < max) {
  6.     low = min;
  7.     hig = max + 1;        // include the max result in the output
  8.   }  else {
  9.     low = max + 1;        // include the max result in the output
  10.     hig = min;
  11.   }
  12.   if (oneTime == 0) {     // you only run srand 1 time.
  13.     srand(time(NULL));
  14.     oneTime++;
  15.   }
  16.   result = (rand() % hig - low)+ low;
  17.   return result;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement