Generating Random Float Values

Generating Random Float Values

To generate random floating numbers, choose a floating point number, divide it by the largest value of int type and multiply the result by the value of a function that generates random integers, say rand():

 #include  // for std::numeric_limits#include  // for rand and srand#include  // for time()using namespace std;int main(){ srand(time(0)); // random seed float rand_val=  100000.0/numeric_limits::max() * rand();}



Share the Post: