How to randomly generate a long integer

Source: Internet
Author: User

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 valuerandFunction 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)

TherandFunction returns the next pseudo-random number in the series. The value ranges from0ToRAND_MAX.

-Function: void Srand( Unsigned int Seed)

This function establishesSeedAs the seed for a new series of pseudo-random numbers. If you callrandBefore a seed has been establishedsrand, It uses the value1As 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_MAXJustrandDoes. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.