Permalink
Browse files

fix random number generation when using interval (TSUN-184)

  • Loading branch information...
1 parent 46a2af5 commit a8574c5bd441ce63bb969d1de39eab051fa607e8 @nniclausse nniclausse committed Jul 12, 2011
Showing with 27 additions and 3 deletions.
  1. +2 −1 src/test/ts_test_all.erl
  2. +23 −0 src/test/ts_test_stats.erl
  3. +1 −1 src/tsung/ts_client.erl
  4. +1 −1 src/tsung/ts_stats.erl
View
@@ -25,4 +25,5 @@ all_test_() -> [ts_test_recorder,
ts_test_match,
ts_test_mon,
ts_test_user_server,
- ts_test_search].
+ ts_test_search,
+ ts_test_stats].
View
@@ -0,0 +1,23 @@
+%%%-------------------------------------------------------------------
+%%% File : ts_test_stats.erl
+%%% Author : Nicolas Niclausse <nicolas@niclux.org>
+%%% Description :
+%%%
+%%% Created : 12 Jul 2011 by Nicolas Niclausse <nicolas@niclux.org>
+%%%-------------------------------------------------------------------
+-module(ts_test_stats).
+
+-compile(export_all).
+
+-include_lib("eunit/include/eunit.hrl").
+-include_lib("ts_profile.hrl").
+-include_lib("ts_config.hrl").
+
+-define(EPSILON,0.01). % error (used to compare floats)
+
+set_dynvar_random_test() ->
+ Min=1,
+ Max=10,
+ R=lists:map(fun(_)->ts_stats:uniform(Min,Max) end, lists:seq(1,1000)),
+ ?assertEqual(Max,lists:max(R)),
+ ?assertEqual(Min,lists:min(R)).
View
@@ -451,7 +451,7 @@ set_dynvars(erlang,{Module,Callback},_Vars,DynData) ->
set_dynvars(code,Fun,_Vars,DynData) ->
Fun({self(),DynData#dyndata.dynvars});
set_dynvars(random,{number,Start,End},Vars,_DynData) ->
- lists:map(fun(_) -> integer_to_list(Start+random:uniform(End-Start)) end,Vars);
+ lists:map(fun(_) -> integer_to_list(ts_stats:uniform(Start,End)) end,Vars);
set_dynvars(random,{string,Length},Vars,_DynData) ->
R = fun(_) -> ts_utils:randomstr(Length) end,
lists:map(R,Vars);
View
@@ -54,7 +54,7 @@ sample (F, X, Param, N) ->
sample(F, [F(Param)|X], Param, N-1 ).
uniform(Min,Max)->
- Min+random:uniform(Max-Min).
+ Min+random:uniform(Max-Min+1)-1.
%% random sample from an exponential distribution
exponential(Param) ->

0 comments on commit a8574c5

Please sign in to comment.