Im a newbie to C and I am not figuring out how to make a function that will generate a double between 0 and 1...
I KNOW NOTHING ABOUT C but managed to get a hello world work...
I tries this function but i think it's not working properly:
float_number = (float) rand()/RAND_MAX;
as when i try to display the num with this forloop it's getting me huge negative or positive numbers
for(i = 0; i < 500; i++){
printf("%d\n", float_number);
}
another thing, what should i add to the code so i dont allow the program to exit directly after execution and so the command prompt stays opened so i can see the results?
$100 per TB is disgusting especially when we have advanced so much in this area, it's because RAM, Flash memory costs so much that creating a small factor, lots of space drives are just through the roof in material requirements.
I use it by choice but only for specific tasks that I have forgotten and it's quicker to ask then spend time wasted finding a decent answer on Google or coding a certain language. I prefer to use it.
I do think that as it gets integrated into everything, when we eventually fully rely on it, I'm talking new gens not older gens like me, that we won't think for ourselves, I mean we will become lazy thinkers, lazy logical answer to problem which will go badly.
But if we don't become fully dependant, we might be OK but I don't think personally we are going to be OK, not for the newer generations. Unless they advance in that space to the next level of intelligence where it can work out its own problems and create ideas for itself.
Question
eliokh
Hello all,
Im a newbie to C and I am not figuring out how to make a function that will generate a double between 0 and 1...
I KNOW NOTHING ABOUT C but managed to get a hello world work...
I tries this function but i think it's not working properly:
as when i try to display the num with this forloop it's getting me huge negative or positive numbers
for(i = 0; i < 500; i++){ printf("%d\n", float_number); }another thing, what should i add to the code so i dont allow the program to exit directly after execution and so the command prompt stays opened so i can see the results?
Thanks in advance.
Elio
Link to comment
https://www.neowin.net/forum/topic/980266-c-random-double-between-0-and-1/Share on other sites
21 answers to this question
Recommended Posts