3454d244359baddb01a24a7b3826e141f5978005
2 # Desc: Pauses a random amount of time. Random distribution is inverse gaussian.
4 # Depends: python 3.7.3
5 # Usage: ./sleepRand.py arg1
6 # Input: arg1: float seconds (mean of inverse gaussian distribution)
7 # Example: python3 sleepRand.py 4.0
9 import math
, time
, random
, sys
12 lambdaFactor
= 4; # spread factor; inversely proportional to variance
15 def randInvGau(mu
, lam
):
16 """Returns random variate of inverse gaussian distribution"""
17 # input: mu: mean of inverse gaussian distribution
18 # lam: shape parameter
19 # output: float sampled from inv. gaus. with range 0 to infinity, mean mu
20 # example: sample = float(randInvGau(1.0,4.0));
21 # Ref/Attrib: doi:10.1080/00031305.1976.10479147
22 nu
= random
.gauss(0,1);
25 xTerm2
= mu
** 2 * y
/ (2 * lam
);
26 xTerm3
= (- mu
/ (2 * lam
)) * math
.sqrt(4 * mu
* lam
* y
+ mu
** 2 * y
** 2);
27 x
= xTerm1
+ xTerm2
+ xTerm3
;
28 z
= random
.uniform(0.0,1.0);
29 if z
<= (mu
/ (mu
+ x
)):
35 arg1
= float(sys
.argv
[1]); # first argument
39 delay
= randInvGau(desMean
, desMean
* lambdaFactor
);
40 #print('DEBUG:delay:' + str(float(delay)));
43 time
.sleep(float(delay
));
45 # Author: Steven Baltakatei Sandoal