Skip to content

Instantly share code, notes, and snippets.

@OverlordEx3
Last active October 24, 2019 17:32
Show Gist options
  • Save OverlordEx3/8d1004eeeccc9a4059378e98e7ebc14e to your computer and use it in GitHub Desktop.
Save OverlordEx3/8d1004eeeccc9a4059378e98e7ebc14e to your computer and use it in GitHub Desktop.
import "dart:core";
Stream<Map<int, int>> getRandomNumbers(int seed, int modulus, int increment, int multiplier, int max) async* {
int prevxn = seed;
int result = 0;
for(int i = 1; i <= max; i++)
{
result = (multiplier*prevxn + increment) % modulus;
yield {i : result};
prevxn = result;
}
}
void main() {
int seed = 7;
int modulus = 16;
int increment = 3;
int multiplier = 5;
int maximum = 32;
print("Calculando números pseudo aleatorios utilizando Congruencia Lineal:");
print("Semilla (x0): $seed");
print("Módulo: $modulus");
print("Multiplicador: $multiplier");
print("Cantidad de iteraciones: $maximum");
/* Print */
getRandomNumbers(seed, modulus, increment, multiplier, maximum).
listen((values) {
print("x${values.keys.first} = ${values.values.first}");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment