import numpy as np import matplotlib.pyplot as plt def plott_histogram_og_par(generator, n=20000): xs = np.array([generator.rand() for _ in range(n + 1)], dtype=float) / generator.modulus fig = plt.figure(figsize=(10, 4.5)) ax = fig.add_subplot(1, 2, 1) ax.hist(xs, bins=50, density=True) ax.axhline(1, color="red", linestyle="--") ax.set_title("Histogram:") ax = fig.add_subplot(1, 2, 2) ax.scatter(xs[:-1], xs[1:], s=0.5) ax.set_title("Påfølgende par i 2D:") ax.set_xlabel("x[n]") ax.set_ylabel("x[n+1]") plt.tight_layout() plt.show() def plott_tripler(generator, n=20000): xs = np.array([generator.rand() for _ in range(n + 2)], dtype=float) / generator.modulus x, y, z = xs[:-2], xs[1:-1], xs[2:] fig = plt.figure(figsize=(15, 4.5)) ax = fig.add_subplot(1, 3, 1) heltall = (xs[:64] * generator.modulus).astype(np.int64) for bit in range(4): ax.step(range(64), ((heltall >> bit) & 1) + 2 * bit, where="mid", label=f"bit {bit}") ax.set_title("Laveste bits i de 64 første tallene") ax.legend(loc="upper right") ax = fig.add_subplot(1, 3, 2, projection="3d") ax.scatter(x, y, z, s=0.5) ax.set_title("Påfølgende tripler (3D)") # Se triplene fra en tilfeldig synsvinkel vinkel, hoyde = np.pi / 3, np.pi / 6 n_hat = np.array([np.cos(hoyde) * np.cos(vinkel), np.cos(hoyde) * np.sin(vinkel), np.sin(hoyde)]) u_hat = np.cross(n_hat, [0, 0, 1]); u_hat /= np.linalg.norm(u_hat) w_hat = np.cross(n_hat, u_hat) punkter = np.stack([x, y, z], axis=1) ax = fig.add_subplot(1, 3, 3) ax.scatter(punkter @ u_hat, punkter @ w_hat, s=0.5) ax.set_title("Tripler sett fra en fast synsvinkel") plt.tight_layout() plt.show()