Advertisement
helos3

rand real number

Oct 4th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5.  
  6. double drand(void) {
  7. double ret = (double)rand() / ((double)rand() + 0.1);
  8. return ret - floor(ret);
  9. }
  10.  
  11. int main(void){
  12. int i = 5;
  13.  
  14. srand(time(NULL));
  15. while ( i-- ){
  16. int n=rand()% 200-100;
  17. float numb=n+drand();
  18. printf("%f\n", numb);
  19.  
  20. }
  21. system("pause");
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement