#include <iostream>
      #include <random>
      using namespace std;
      
      float randFloat(int hi = 0, int lo = 0){
        if(hi == 0){
          //random number in [0,1)
          return static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
        }else if(lo == 0){
          //random number in [0,hi)
          return static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/hi));
        }else{
          //random number in [lo, hi)
          return lo + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(hi-lo)));
        }
      }
      
      Cpp language logo

      Random float

      0

      0

      avatar
      Giovanny Gongora
      Codiga's C++ Recipes

      Generate a random float

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.