Browse files

Use sfmt-erlang for random number generation

  • Loading branch information...
1 parent 0eda58a commit dcf5573cafdf661ec3666053d0c9531c7a072aef @thomasc thomasc committed Apr 16, 2012
Showing with 20 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +4 −1 Makefile
  3. BIN rebar
  4. +4 −0 rebar.config
  5. +1 −1 src/proper.app.src
  6. +7 −7 src/proper_arith.erl
  7. +3 −3 src/proper_gen.erl
View
1 .gitignore
@@ -4,6 +4,7 @@
*.tar.gz
*.beam
*.app
+deps/
doc/*.html
doc/*.css
doc/*.png
View
5 Makefile
@@ -22,13 +22,16 @@
.PHONY: default all compile dialyze check_escripts tests doc clean distclean rebuild retest
-default: compile
+default: get-deps compile
all: compile doc
include/compile_flags.hrl:
./write_compile_flags $@
+get-deps:
+ ./rebar get-deps
+
compile:
./rebar compile
View
BIN rebar
Binary file not shown.
View
4 rebar.config
@@ -36,3 +36,7 @@
{pre_hooks, [{compile, "make include/compile_flags.hrl"}]}.
{post_hooks, [{clean, "./clean_doc.sh"}]}.
+{deps, [
+ {sfmt, ".*", {git, "https://github.com/jj1bdx/sfmt-erlang.git",
+ {branch, "master"}}}
+ ]}.
View
2 src/proper.app.src
@@ -26,5 +26,5 @@
[{description, "A QuickCheck-inspired property-based testing tool for Erlang"},
{vsn, "1.0"},
{registered, []},
- {applications, [compiler,kernel,stdlib]},
+ {applications, [compiler,kernel,stdlib,sfmt]},
{env, []}]}.
View
14 src/proper_arith.erl
@@ -213,20 +213,20 @@ remove_n(N, {List,Acc}) ->
%% calling any random function from this module.
-spec rand_start(seed()) -> 'ok'.
rand_start(Seed) ->
- _ = random:seed(Seed),
+ _ = sfmt:seed(Seed),
%% TODO: read option for RNG bijections here
ok.
-spec rand_reseed() -> 'ok'.
rand_reseed() ->
%% TODO: This should use the pid of the process somehow, in case two
%% spawned functions call it simultaneously?
- _ = random:seed(now()),
+ _ = sfmt:seed(now()),
ok.
-spec rand_stop() -> 'ok'.
rand_stop() ->
- erase(random_seed),
+ erase(sfmt_seed),
ok.
-spec rand_int(non_neg_integer()) -> integer().
@@ -239,26 +239,26 @@ rand_non_neg_int(Const) ->
-spec rand_int(integer(), integer()) -> integer().
rand_int(Low, High) when is_integer(Low), is_integer(High), Low =< High ->
- Low + random:uniform(High - Low + 1) - 1.
+ Low + sfmt:uniform(High - Low + 1) - 1.
-spec rand_float(non_neg_integer()) -> float().
rand_float(Const) ->
X = rand_non_neg_float(Const),
- case random:uniform(2) of
+ case sfmt:uniform(2) of
1 -> X;
2 -> -X
end.
-spec rand_non_neg_float(non_neg_integer()) -> float().
rand_non_neg_float(Const) when is_integer(Const), Const >= 0 ->
- case random:uniform() of
+ case sfmt:uniform() of
1.0 -> rand_non_neg_float(Const);
X -> Const * zero_one_to_zero_inf(X)
end.
-spec rand_float(float(), float()) -> float().
rand_float(Low, High) when is_float(Low), is_float(High), Low =< High ->
- Low + random:uniform() * (High - Low).
+ Low + sfmt:uniform() * (High - Low).
-spec zero_one_to_zero_inf(float()) -> float().
%% This function must return only non-negative values and map 0.0 to 0.0, but
View
6 src/proper_gen.erl
@@ -581,9 +581,9 @@ function_body(Args, RetType, {Seed1,Seed2}) ->
true ->
RetType;
_ ->
- SavedSeed = get(random_seed),
- put(random_seed, {Seed1,Seed2,erlang:phash2(Args,?SEED_RANGE)}),
+ SavedSeed = get(sfmt_seed),
+ sfmt:seed({Seed1,Seed2,erlang:phash2(Args,?SEED_RANGE)}),
Ret = clean_instance(generate(RetType)),
- put(random_seed, SavedSeed),
+ put(sfmt_seed, SavedSeed),
proper_symb:internal_eval(Ret)
end.

0 comments on commit dcf5573

Please sign in to comment.