Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. include<stdio.h>
  2. #include<time.h>
  3.  
  4. float random(int *startwert);
  5. float transf(float zufall);
  6.  
  7. int main(void)
  8. {
  9.   int i,x1;
  10.   float z, zufall;
  11.  
  12.   printf("10 Wuerfe mit einem 6-seitigen Wuerfel:\n");
  13.  
  14.   x1=time(NULL) % 10000;
  15.  
  16.   for(i=1; i<=10; i++)
  17.   {
  18.     zufall=random(&x1);
  19.     z=transf(zufall);
  20.     printf(" %1.0f \n",z);
  21.   }
  22.  
  23.  
  24.   return 0;
  25.  
  26. }
  27.  
  28.  
  29. float random(int *startwert)
  30. {
  31.   float zufall;
  32.    
  33.   *startwert=(*startwert*7141+54773) % 253177;
  34.   zufall=*startwert/253177.0;  
  35.   return zufall;
  36. }
  37.  
  38.  
  39. float transf(float zufall)
  40. {
  41.   float z;
  42.  
  43.   z=(int)(6*zufall+1);
  44.   return z;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement