Lines 20
##### Keywords
floating point (1) random (8) real (1)
##### Permissions
Owner: schram
Viewable by Everyone
Editable by All Siafoo Users
Easily highlight source code for your blog with our Syntax Highlighter.

# Floating Point Random Number 1

 In Brief frand() - Simple C code designed to generate a pseudorandom 32-bit floating point number.
 Language C
# 's
` 1// frand() - this function will generate a pseudorandom floating point variable 2float frand(float range) 3{ 4	unsigned int sign, exponent, mantissa; 5	unsigned int final_rand; 6	float result; 7 8	// set the sign and the exponent 9	sign=0;					// positive10	exponent=127;			// 1.0*whatever we get11	mantissa=8388607;		// 2.01213	// generate a 23-bit integer for our mantissa14	mantissa = rand() + ((rand() >> 7) << 15);1516	// now get the integer result of all our stuff, shifting as necessary17	integer_result=(sign<<31)+(exponent<<23)+mantissa;1819	memcpy(&result,&integer_result,sizeof(float));2021	// subtract the result by 1.022	result-=1.0f;2324	// return the floating point result, multiplied by the range25	return(result*result);26} // end frand()`

frand() - Simple C code designed to generate a pseudorandom 32-bit floating point number.