SHARE
TWEET

Untitled

a guest Sep 17th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import "dart:core";
  2.  
  3. Stream<Map<int, int>> getRandomNumbers(int seed, int modulus, int increment, int multiplier, int max) async* {
  4.   int prevxn = seed;
  5.   int result = 0;
  6.  
  7.   for(int i = 1; i <= max; i++)
  8.   {
  9.     result = (multiplier*prevxn + increment) % modulus;
  10.     yield {i : result};
  11.     prevxn = result;
  12.   }
  13. }
  14.                
  15. void main() {
  16.   int seed = 7;
  17.   int modulus = 16;
  18.   int increment = 3;
  19.   int multiplier = 5;
  20.   int maximum = 32;
  21.  
  22.   print("Calculating pseudorandom numbers:");
  23.   print("x0: $seed, modulus:$modulus, step:$increment, multiplier:$multiplier, iteration count:$maximum");
  24.   /* Print */
  25.   getRandomNumbers(seed, modulus, increment, multiplier, maximum).listen((values) => print("x${values.keys.first} = ${values.values.first}"));
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top