Some functions in GCC can help generate integers, but they are all Int.
19.8.1 Iso c random number Functions
This section describes the random number functions that are part of the iso c standard.
To use these facilities, you should include the header fileStdlib. hIn your program.
-Macro: int
Rand_max
The value of this macro is an integer constant representing the largest valuerand
Function can return. In the GNU Library, it is2147483647
, Which is the largest signed integer representable in 32 bits. In other libraries,
It may be as low32767
.
-Function: int
Rand( Void)
Therand
Function returns the next pseudo-random number in the series. The value ranges from0
ToRAND_MAX
.
-Function: void
Srand( Unsigned int Seed)
This function establishesSeedAs the seed for a new series of pseudo-random numbers. If you callrand
Before a seed has been establishedsrand
, It uses the value1
As a default seed.
To produce a different pseudo-random series each time your program is run, dosrand (time (0))
.
Posix.1 extended the c Standard functions to support reproducible random numbers in multi-threaded programs. However, the extension is badly designed and unsuitable for serious work.
-Function: int
Rand_r( Unsigned int * Seed)
This function returns a random number in the range 0RAND_MAX
Justrand
Does. However, all its state is stored inSeedArgument. This means the RNG's state can only have as your bits as the typeunsigned
int
Has. This is far too few to provide a good RNG.
If your program requires a reentrant RNG, we recommend you use the reentrant GNU extensions to the svid random number generator. The posix.1 interface shoshould only be used when the GNU extensions are not available.
For more information, see
Http://meizhe143.blog.163.com/blog/static/38938362007102995121360/
But how to generate a long integer?
Can I generate an int-type random number twice, and then use the bitwise operation to regard one number as a high value, and the other as a low value to spell out a long integer.