# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 線型合同法
#
# $$
# X_{n+1} \equiv (aX_n + c)  \mod m
# $$

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
# %matplotlib inline
sns.set('poster', 'whitegrid', 'dark', font_scale=1, rc={"lines.linewidth": 2, 'grid.linestyle': '-'})


class lcg:
    def __init__(self, seed, a=12, c=5, m=127):
        lcg.y = seed
        lcg.a = a
        lcg.c = c
        lcg.m = m 
    def rand(self):
        self.y = (self.a * self.y + self.c) % self.m
        return self.y


a = lcg(5)
y = np.array([a.rand() for n in range(126)])

print(y)
print(np.roll(y,-1))

len(np.unique(y))

fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)
ax.set_xlim(0,127)
ax.set_ylim(0,127)
ax.set_xlabel('$x_n$')
ax.set_ylabel('$x_{n+1}$')
ax.plot(y, np.roll(y,-1), '.')
# plt.savefig('LCGLattice.pdf', bbox_inches='tight')

# LADAU

a = lcg(5, a=65539, m=2**31)
z = np.array([a.rand() for n in range(10000)])

fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)
ax.set_xticks([])
ax.set_yticks([])
ax.set_xlabel('$x_n$')
ax.set_ylabel('$x_{n+1}$')
ax.set_xlim(0, 2**31)
ax.set_ylim(0, 2**31)
ax.plot(z, np.roll(z,-1), ',')
# plt.savefig("LADAU2D.pdf", bbox_inches='tight')

fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111, projection='3d')
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
#ax.set_xlabel('$x_n$')
#ax.set_ylabel('$x_{n+1}$')
#ax.set_zlabel('$x_{n+2}$')
ax.set_xlim(0, 2**31)
ax.set_ylim(0, 2**31)
ax.set_zlim(0, 2**31)
ax.view_init(elev=45, azim=60)
ax.plot(z, np.roll(z,-1), np.roll(z,-2),',')
# plt.savefig("LADAU3D.pdf", bbox_inches='tight')

StarcoderdataJupyterScriptsDedupFiltered