Example Function Program Documentation - GarethG/ProjectRinzler GitHub Wiki

genRandFloat

Generate a random float value.

float genRandFloat( float a, float b )
{
    return ( (b-a)*( (float)rand() / RAND_MAX ) )+a;
}

Parameters:

  • a - Sets the lower boundary of the number generation.
  • b - Sets the higher.

Full description:

Full description is descriptive, this one isn't.


Example Use:

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

float genRandFloat( float a, float b );

int main(void)
{
	int i;
	float low = 0.3, high = 0.6;

	//Seed with the time.
	srand ( (unsigned)time ( NULL ) );

	//Seed 20 random numbers between low and high
	for(i = 0; i < 20; i ++)
		printf( "%f\n", genRandFloat(low, high) );

	return 0;


}

float genRandFloat( float a, float b )
{
    return ( (b-a)*( (float)rand() / RAND_MAX ) )+a;
}

⚠️ **GitHub.com Fallback** ⚠️