Several methods of generating random numbers in Erlang "Erlang"

Source: Internet
Author: User

Erlang has three ways to produce a random number

Random:uniform ().

This function is provided by the Erlang Library random module. This is generally used.

1> Random:uniform (). 0.4435846174457203


Erlang:now ().

Use the current time as a random believe a lot of people have done it. So if you don't have a lot of demands, you can do the same.

1> Erlang:now (). { 1419,831449,715000}


Crypto:strong_rand_bytes (N).

The crypto module is a module for encryption. The Strong_rand_bytes function produces a uniform n-byte random number. The binary data is returned. Such as

1> <<A:32,B:32,C:32>> = Crypto:strong_rand_bytes (a). <<154,106,144,218,65,238,246,170,246,70,252,167>>2> A. 2590675162

You can shengcheng,3 a 32-bit random number, which is equivalent to 3 random integers.

Several methods of generating random numbers in Erlang "Erlang"

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.