forked from MaterSim/ComputationalPhysics300
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lec 13 hw part 3.py
81 lines (66 loc) · 1.87 KB
/
lec 13 hw part 3.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 8 03:41:19 2018
@author: towar
"""
# A code to generate pseudo random numbers
import matplotlib.pyplot as plt
import numpy as np
# a few constants
N = 1000
N2 = 2*N +1
notzero = 1
# define some storage space
resultsx = np.zeros(N2)
resultsacm = []
# storaage for graphing a,c,m values as tuples of x y z
# m
mline = []
# a
aline = []
#c
cline = []
# define function to test N number of different a c and m values
# then store them to graph later
def randoint(x,N2):
# random variable to decide what is positive or negative
randomvarx = 1
randomvara = -1
randomvarc = -1
# counter variables
acmcount = 0
l = 0
# init random tries
x = np.random.randint(11) + notzero*randomvarx
a = np.random.randint(21) + notzero*randomvara
c = np.random.randint(3) + notzero*randomvarc
m = np.random.randint(4) + notzero
#print(acmcount, 'acmcount')
while l < N2:
x = (a*x+c)%m
resultsx[l] = x
l += 1
# test random tries to see if they fit the criteria
for i in range(N2):
if -6 < resultsx[i] and resultsx[i] < 6:
acmcount += 1
# store a,c,m values if they fit
if acmcount == N2:
resultsacm.append((a,c,m))
aline.append(a)
cline.append(c)
mline.append(m)
#print(resultsx)
#return resultsx
# run the function
for i in range(N):
randoint(i,N2)
# print the resulting successes
print(resultsacm)
# plot successes to try and visualize a pattern
plt.figure(figsize = (15,15))
ax = plt.axes(projection='3d')
# Data for a three-dimensional line
ax.plot3D(aline, cline, mline, 'none')
# Data for three-dimensional scattered points
ax.scatter3D(aline, cline, mline, c='r', cmap='Greens');