Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to generate random floating point number between 0 and 1 in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
int main() {
    srand((unsigned int)time(NULL));

    for (int i = 0; i < 25; i++)
        printf("%f\n", (float)rand() / (float)RAND_MAX);
         
    return 0;
}
 
 
/*
run:
 
0.430166
0.561872
0.093331
0.608843
0.272517
0.298066
0.864854
0.731596
0.103419
0.936059
0.634556
0.131789
0.719566
0.396311
0.060300
0.379816
0.690235
0.558314
0.249370
0.870029
0.144419
0.482467
0.460026
0.921403
0.886848
 
*/

 



answered Jan 3, 2021 by avibootz

Related questions

...