Skip to content

Commit

Permalink
rebaring: allow overriding RNG by defining macros
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp committed May 20, 2018
1 parent 1118786 commit ac78d4a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
sudo: false
language: erlang
script: REBAR=~/rebar3 make all
script:
- ~/rebar3 compile
- REBAR=~/rebar3 make all
- rm -rf _build
- ./configure --use-sfmt
- make fast && cd deps/sfmt && make && cd -
- make all

otp_release:
- 20.3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ compile:
$(REBAR) compile

dialyzer: .plt/proper_plt compile
dialyzer -n -nn --plt $< -Wunmatched_returns ebin $(find . -path 'deps/*/ebin/*.beam')
dialyzer -n -nn --plt $< -Wunmatched_returns ebin $(find . -path 'deps/*/ebin/*.beam') $(find . -path '_build/default/lib/*/ebin')

.plt/proper_plt: .plt
dialyzer --build_plt --output_plt $@ --apps erts kernel stdlib compiler crypto syntax_tools
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ Quickstart guide
a `make all` call; in that case, you are going to need the `syntax_tools`
application and a recent version of `EDoc`).
Optionally, sfmt-erlang can be selected as an alternative random number
generator using `./configure --use-sfmt` before running `make`.
generator using `./configure --use-sfmt` before running `make`, or with rebar3:
```erlang
{deps, [sfmt]}. %% Once sfmt-erlang supports rebar3 compilation.
{overrides, [{override, proper, [{erl_opts, [{d, 'USE_SFMT'}]}]}]}.
```
* Add PropEr's base directory to your Erlang library path, using one of the
following methods:
1. `ERL_LIBS` environment variable: Add the following line to your shell
Expand Down
43 changes: 28 additions & 15 deletions include/proper_internal.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,40 @@
%% Random generator selection
%%------------------------------------------------------------------------------

-ifndef(USE_SFMT).
- ifndef(USE_EXSPLUS).
- ifndef(USE_RANDOM).
- ifdef(AT_LEAST_19).
%% for 19.x use 'rand' module
- define(USE_EXSPLUS, true).
- else.
%% for 18.x and older use 'random' module
- define(USE_RANDOM, true).
- endif.
- endif.
- endif.
-endif.

-ifdef(USE_SFMT).
-define(RANDOM_MOD, sfmt).
-define(SEED_NAME, sfmt_seed).
-define(RNG_SET_SEED(Seed), ?RANDOM_MOD:seed(Seed)).

-else.
-define(RNG_SET_SEED(Seed), sfmt:seed(Seed)).
-define(RNG_UNIFORM(), sfmt:uniform()).
-define(RNG_UNIFORM(UpperBound), sfmt:uniform(UpperBound)).
-endif.

-ifdef(AT_LEAST_19).
%% for 19.x use the 'rand' module
-define(RANDOM_MOD, rand).
-ifdef(USE_EXSPLUS).
-define(SEED_NAME, rand_seed).
-define(RNG_SET_SEED(Seed), ?RANDOM_MOD:seed(exsplus,Seed)).
-else.
-define(RANDOM_MOD, random).
-define(SEED_NAME, random_seed).
-define(RNG_SET_SEED(Seed), ?RANDOM_MOD:seed(Seed)).
-endif.
-define(RNG_SET_SEED(Seed), rand:seed(exsplus,Seed)).
-define(RNG_UNIFORM(), rand:uniform()).
-define(RNG_UNIFORM(UpperBound), rand:uniform(UpperBound)).
-endif.

-define(RNG_UNIFORM(), ?RANDOM_MOD:uniform()).
-define(RNG_UNIFORM(UpperBound), ?RANDOM_MOD:uniform(UpperBound)).
-ifdef(USE_RANDOM).
-define(SEED_NAME, random_seed).
-define(RNG_SET_SEED(Seed), random:seed(Seed)).
-define(RNG_UNIFORM(), random:uniform()).
-define(RNG_UNIFORM(UpperBound), random:uniform(UpperBound)).
-endif.

%%------------------------------------------------------------------------------
%% Line annotations
Expand Down

0 comments on commit ac78d4a

Please sign in to comment.