Answers for "random float number c"

C
1

c get random float

//random float between 0 and a
float x = (float)rand()/(float)(RAND_MAX/a);
Posted by: Guest on May-31-2021
0

random float number in C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    srand(time(NULL));

    float max = 1.5;
  	//algorithm for creating a random number 
  				//(float cast) (float cast)	(RAND_MAX) is a costant included in the lib time.h
    printf("%f\n", ((float)rand()/(float)(RAND_MAX)) * max);
    return 0;
}
Posted by: Guest on March-03-2022

Code answers related to "C"

Browse Popular Code Answers by Language