random.c revision 206918
1 2/* 3=============================================================================== 4 5This C source file is part of TestFloat, Release 2a, a package of programs 6for testing the correctness of floating-point arithmetic complying to the 7IEC/IEEE Standard for Floating-Point. 8 9Written by John R. Hauser. More information is available through the Web 10page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'. 11 12THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 13has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 14TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 15PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 16AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 17 18Derivative works are acceptable, even for commercial purposes, so long as 19(1) they include prominent notice that the work is derivative, and (2) they 20include prominent notice akin to these four paragraphs for those parts of 21this code that are retained. 22 23=============================================================================== 24*/ 25 26#include <stdlib.h> 27#include "milieu.h" 28#include "random.h" 29 30uint8 randomUint8( void ) 31{ 32 33 return (bits8) ( rand()>>4 ); 34 35} 36 37uint16 randomUint16( void ) 38{ 39 40 return ( ( rand() & 0x0FF0 )<<4 ) | ( ( rand()>>4 ) & 0xFF ); 41 42} 43 44uint32 randomUint32( void ) 45{ 46 47 return 48 ( ( (uint32) ( rand() & 0x0FF0 ) )<<20 ) 49 | ( ( (uint32) ( rand() & 0x0FF0 ) )<<12 ) 50 | ( ( rand() & 0x0FF0 )<<4 ) 51 | ( ( rand()>>4 ) & 0xFF ); 52 53} 54 55#ifdef BITS64 56 57uint64 randomUint64( void ) 58{ 59 60 return ( ( (uint64) randomUint32() )<<32 ) | randomUint32(); 61 62} 63 64#endif 65 66