""" Linear kongruenter Zufallszahlengenerator """ import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d # Klasse fuer eigenen LCG class MyRandom(): def __init__( self, a, c, m, seed ): self._a = a self._c = c self._m = m self._xi = seed def rand( self, n = 1 ): values = np.zeros( n ) for i in np.arange( n ): self._xi = ( self._a * self._xi + self._c ) % self._m values[i] = self._xi / self._m return values # Instanz des LCG mit speziellen Parameterwerten erzeugen random = MyRandom( 11679, 32431, 129029, 10 ) # Plot mit aktueller Achse in 3D fig = plt.figure() ax = fig.add_subplot( projection = '3d' ) # Zufallszahlen etwas umstaendlich farbkodiert, zeigen Hyperflaechen in 3D x = [] y = [] z = [] col = [] for i in np.arange( 10000 ): x.append( random.rand() ) y.append( random.rand() ) zval = random.rand() z.append( zval ) if( zval < 0.33 ): col.append( 'red' ) elif( zval < 0.66 ): col.append( 'green' ) else: col.append( 'blue' ) ax.scatter( x, y, z, s=1, c=col ) plt.show()