fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. for (int i = 0; i < 10; i++) {
  6. int r = rand();
  7. // Assumindo que RAND_MAX seja pelo menos 2^32-1
  8. //printf("r = %d\n");
  9.  
  10. // zera bit de sinal, expoente
  11. r = (r & 0x3FFFFFFF) | 0x3F800000; // zera bits de sinal de
  12. //printf("r = %d\n");
  13.  
  14. // gera numero entre 1 e 2
  15. float f = *((float *)&r);
  16. //printf("f = %f\n", f);
  17.  
  18. // normaliza entre 0 e 1
  19. f = f - 1;
  20. //printf("f = %f\n", f);
  21.  
  22. float min = -270.33f;
  23. float max = -47.5f;
  24.  
  25. float fRand = min + (f * (max - min));
  26. printf("fRand = %f\n", fRand);
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
fRand = -250.708588
fRand = -55.961029
fRand = -164.842010
fRand = -181.053497
fRand = -185.270538
fRand = -142.614868
fRand = -88.272224
fRand = -121.752258
fRand = -245.746063
fRand = -88.431946