fork download
  1. #include <iostream>
  2. #include <float.h>
  3. #include <cstdlib>
  4.  
  5. double randD1(){
  6. return ((double)std::rand()/((double)RAND_MAX));
  7. }
  8. double randDMax(){
  9. return randD1()*DBL_MAX;
  10. }
  11. int main(){
  12. std::cout<<"--0..1-----------"<<std::endl;
  13. for(int i=0; i<10; ++i){
  14. std::cout<<randD1()<<std::endl;
  15. }
  16. std::cout<<"--0..DBL_MAX-----"<<std::endl;
  17. for(int i=0; i<10; ++i){
  18. std::cout<<randDMax()<<std::endl;
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
--0..1-----------
0.840188
0.394383
0.783099
0.79844
0.911647
0.197551
0.335223
0.76823
0.277775
0.55397
--0..DBL_MAX-----
8.58213e+307
1.13052e+308
6.55771e+307
9.22937e+307
1.71182e+308
1.64704e+308
1.14281e+308
1.28948e+308
2.54558e+307
1.09114e+308