Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Programm: random.C // berechnet eine Folge von Pseudozufallszahlen #include int main() { // Lineare Kongruenzmethode zur Erzeugung von // Pseudozufallszahlen x_0, x_1, x_2, ... // mit Hilfe der Formel x_i = a * x_(i-1) % m const unsigned int m = 65536; // Modulus, 2^16 const unsigned int a = 47485; // Multiplikator const unsigned int x0 = 1; // Startwert // lies Anzahl zu erzeugender Zahlen ein std::cout << "Anzahl von Pseudozufallszahlen: "; unsigned int anzahl; std::cin >> anzahl; // Erzeugung und Ausgabe unsigned int x = x0; // aktuelle Zufallszahl std::cout << "Folge von " << anzahl << " Zufallszahlen: "; while (anzahl > 0) { std::cout << x << " "; x = a * x % m; anzahl = anzahl - 1; } std::cout << std::endl; return 0; }