76a32e10172aa696e911e11a068817a3fe9d6c33
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 def randInvGau(mu
, lam
):
13 """Returns random variate of inverse gaussian distribution"""
14 # Ref/Attrib: doi:10.1080/00031305.1976.10479147
15 nu
= random
.gauss(0,1);
18 xTerm2
= mu
** 2 * y
/ (2 * lam
);
19 xTerm3
= (- mu
/ (2 * lam
)) * math
.sqrt(4 * mu
* lam
* y
+ mu
** 2 * y
** 2);
20 x
= xTerm1
+ xTerm2
+ xTerm3
;
21 z
= random
.uniform(0.0,1.0);
22 if z
<= (mu
/ (mu
+ x
)):
28 arg1
= float(sys
.argv
[1]); # first argument
32 lambdaFactor
= 4; # spread factor; inversely proportional to variance
35 delay
= randInvGau(desMean
, desMean
* lambdaFactor
);
36 #print('DEBUG:delay:' + str(float(delay)));
39 time
.sleep(float(delay
));