Skip to content

Instantly share code, notes, and snippets.

@biboudis
Created February 20, 2012 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biboudis/1869437 to your computer and use it in GitHub Desktop.
Save biboudis/1869437 to your computer and use it in GitHub Desktop.
A random number, observable generator in Rx, without closing over a Random value.
IDisposable generator = Observable.Generate<Tuple<Random, int>, int>(
new Tuple<Random, int>(new Random(), 0),
value => value.Item2 < 100,
value => new Tuple<Random, int>(value.Item1, value.Item2 + 1),
value => value.Item1.Next(0, 100), scheduler).Subscribe(Console.WriteLine);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment