Three Methods of Generating Random Numbers in Erlang


Erlang has three ways to produce random numbers


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

Copy codeThe code is as follows:
1> random:uniform().


Use the current time as a random belief that many people have done it. So if you don’t have too many requirements, of course you can do the same.

Copy codeThe code is as follows:
1> erlang:now().


Crypto module is used for encryption. The strong_rand_bytes function can generate uniform random numbers of N bytes. It returns binary data. as

Copy codeThe code is as follows:
1> <<A:32,B:32,C:32>> = crypto:strong_rand_bytes(12).
2> A.

That’s shengcheng, three 32-bit random numbers, equivalent to three random integers.

Recommended Today

JS generate guid method

JS generate guid method Globally unique identification(GUID) is an algorithm generatedBinaryCount Reg128 bitsNumber ofidentifier , GUID is mainly used in networks or systems with multiple nodes and computers. Ideally, any computational geometry computer cluster will not generate two identical guids, and the total number of guids is2^128In theory, it is difficult to make two […]