diff options
author | Mickael Remond <mremond@process-one.net> | 2016-11-09 09:04:58 +0100 |
---|---|---|
committer | Mickael Remond <mremond@process-one.net> | 2016-11-09 09:04:58 +0100 |
commit | 42bede77a1a36c6bbc1ce3c2728e8c3dd78eb5f2 (patch) | |
tree | 677c46157270f24a40200ebb21beb5ba0397d358 /src/randoms.erl | |
parent | Expose unregister API command (diff) | |
parent | Support several groups separated by ; in add_rosteritem command (diff) |
Merge branch 'master' of github.com:processone/ejabberd
Diffstat (limited to 'src/randoms.erl')
-rw-r--r-- | src/randoms.erl | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/randoms.erl b/src/randoms.erl index 52fceef4e..1353f48af 100644 --- a/src/randoms.erl +++ b/src/randoms.erl @@ -27,14 +27,29 @@ -author('alexey@process-one.net'). --export([get_string/0]). +-export([get_string/0, uniform/0, uniform/1, bytes/1]). -export([start/0]). +-define(THRESHOLD, 16#10000000000000000). + start() -> ok. get_string() -> - R = crypto:rand_uniform(0, 16#10000000000000000), + R = crypto:rand_uniform(0, ?THRESHOLD), jlib:integer_to_binary(R). +uniform() -> + crypto:rand_uniform(0, ?THRESHOLD)/?THRESHOLD. + +uniform(N) -> + crypto:rand_uniform(1, N+1). + +-ifdef(STRONG_RAND_BYTES). +bytes(N) -> + crypto:strong_rand_bytes(N). +-else. +bytes(N) -> + crypto:rand_bytes(N). +-endif. |