Hi friends how to generate random numbers in between 0 to 1. I need to generate around 100 random numbers in between 0 to 1..please help me..
Thanks,
read a random number into a float between the range of 0 and 100, then divide by 100 to get a number from 0 to 0.9999
http://www.google.com/search?hl=pl&q=generating+random+numbers+c%2B%2B&lr=
First result for me is ling to DaniWeb article on generating random numbers.
Yes, what Ancient Dragon sead will work fine, to save some time you could define it as a macro.
#include<iostream>
#define rand_f(n) (((rand()%10000)/10000.0f)*n)
int main() {
for (int i = 0; i < 100; i++) {
std::cout << rand_f(1) << '\n';
}
std::cin.ignore();
return 0;
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.