27e98d7d520b0ac511c413145e98814c949ba649
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 # input: mu: mean of inverse gaussian distribution
15 # lam: shape parameter
16 # output: float sampled from inv. gaus. with range 0 to infinity, mean mu
17 # example: sample = float(randInvGau(1.0,4.0));
18 # Ref/Attrib: doi:10.1080/00031305.1976.10479147
19 nu
= random
.gauss(0,1);
22 xTerm2
= mu
** 2 * y
/ (2 * lam
);
23 xTerm3
= (- mu
/ (2 * lam
)) * math
.sqrt(4 * mu
* lam
* y
+ mu
** 2 * y
** 2);
24 x
= xTerm1
+ xTerm2
+ xTerm3
;
25 z
= random
.uniform(0.0,1.0);
26 if z
<= (mu
/ (mu
+ x
)):
32 arg1
= float(sys
.argv
[1]); # first argument
36 lambdaFactor
= 4; # spread factor; inversely proportional to variance
39 delay
= randInvGau(desMean
, desMean
* lambdaFactor
);
40 #print('DEBUG:delay:' + str(float(delay)));
43 time
.sleep(float(delay
));
45 # Author: Steven Baltakatei Sandoal