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?
If you're using a webcam for Zoom calls, then any 720p or 1080p cam will do. If on the other hand you want high quality video for streaming or recording, then consider using a DSLR or mirrorless camera, because 99% of 4k webcams will have a tough time achieving same results.
Kind of glad I upgraded to S26 Ultra 1TB this year, with trade-in and discounts it cost me €1199, that's only €119 more than the S23 Ultra (256 GB) cost me. Last time I bought it via my phone provider outright with committing to two years, now via Samsung.com
I reckon the S27 series will be more expensive too.
Recent Achievements
Huge Trailer earned a badge Week One Done
Classifyskilleducation earned a badge Week One Done
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