-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear_congruence.py
47 lines (38 loc) · 1.15 KB
/
linear_congruence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import math
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from scipy.stats import gaussian_kde
import random
def linear_congruence(seed,A,C,M,steps):
X = []
next_element = seed
for i in range(steps):
X += [next_element/M]
next_element = (next_element*A+C) % M
emp_mean = sum(X)/steps
emp_var = 0
for j in X:
emp_var += (j - emp_mean)**2
emp_var /= steps
print("Moyenne empirique: ", emp_mean)
print("Variance empirique: ", emp_var)
print("\n")
return X
#Python random function
def random_generator_computer(steps):
Y = []
for i in range(steps):
Y += [random.random()]
emp_mean_comp = np.mean(Y)
emp_var_comp = np.var(Y,dtype=np.float64)
print("Moyenne empirique par ordinateur: ", emp_mean_comp)
print("Variance empirique par ordinateur: ", emp_var_comp)
return Y
data1 = linear_congruence(3,158348089,0,2**31-1,300000)
data2 = random_generator_computer(300000)
#qsdsqdsqd
sns.set_style('whitegrid')
sns.kdeplot(np.array(data1),bw=0.1)
sns.kdeplot(np.array(data2),bw=0.1)
plt.show()