fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. unsigned int rand32bit(void){
  5.  
  6. unsigned int i, x, r = 0;
  7.  
  8. x = rand();
  9. if (x & 0x4000) {
  10. r += 0;
  11. putchar('0');
  12. }
  13. else {
  14. r += 1;
  15. putchar('1');
  16. }
  17.  
  18. for (i = 0; i<31; i++){
  19. x = rand();
  20. if (x & 0x4000) {
  21. r <<= 1; r += 0;
  22. putchar('0');
  23. }
  24. else {
  25. r <<= 1; r += 1;
  26. putchar('1');
  27. }
  28. }
  29.  
  30. putchar('\n');
  31. return r;
  32. }
  33.  
  34. int main()
  35. {
  36. int i;
  37. printf("RAND_MAX=%x\n", RAND_MAX);
  38. for (i = 0; i < 10; i++) {
  39. rand32bit();
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
RAND_MAX=7fffffff
01100010100001101011100011000001
00001010011110111100011101010110
10000011100110000100000110111101
00010100110100100111101111100100
00111011100011011011000010111101
10010010000101100010000101111011
11111100111001001010000100110010
00001001101011110010100100110111
11111101100101000011011010000111
00100000001110111011100111110111