fork(11) download
  1. #include <cfloat> // DBL_MAX
  2. #include <cmath> // std::nextafter
  3. #include <random>
  4. #include <iostream>
  5.  
  6. int main()
  7. {
  8. const double start = -1.0;
  9. const double end = 1.0;
  10.  
  11. std::random_device rd;
  12. std::mt19937 gen(rd());
  13. std::uniform_real_distribution<> dis(start, std::nextafter(end, DBL_MAX));
  14.  
  15. for (auto i = 0; i < 100; ++i)
  16. {
  17. std::cout << dis(gen) << "\n";
  18. }
  19. std::cout << std::endl;
  20. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
0.934114
-0.125155
0.44114
-0.429883
-0.145034
-0.396043
-0.949989
0.811492
0.39321
-0.845814
0.937261
0.443281
0.299098
0.564552
-0.318866
0.853572
0.605249
-0.96805
0.662167
0.216535
-0.324268
0.961125
-0.174896
-0.361494
0.285389
-0.00619651
0.716233
0.947658
-0.609413
0.647042
0.334661
0.108747
0.512068
-0.944978
0.79564
0.703829
-0.0640978
-0.949015
-0.026395
-0.369833
-0.938078
-0.129683
-0.890853
0.266113
0.011489
0.736704
0.826294
-0.885531
-0.451989
0.891476
-0.785844
-0.519498
-0.464232
0.754212
0.99193
0.419462
-0.7681
-0.775289
-0.964843
0.580281
0.57493
0.299869
0.344372
-0.693428
0.483982
0.281516
0.744408
0.143526
-0.128739
0.826598
-0.747737
-0.690922
-0.20874
0.411856
-0.55394
-0.687795
-0.658983
0.703717
-0.688702
0.138251
-0.362084
0.0379065
-0.976946
0.406712
0.440964
-0.242345
-0.462501
-0.327733
-0.498235
-0.594218
-0.11345
0.751402
0.631945
-0.678224
-0.620145
-0.380282
0.100319
-0.577019
0.121617
-0.975822