c# Programming Glossary: rng.next
Non-repetitive random number C# http://stackoverflow.com/questions/1011198/non-repetitive-random-number-c-sharp of course public int NextNumber Random rng return rng.Next 20 1 then the caller can reuse the instance appropriately. If.. at my StaticRandom class in MiscUtil . Note that using rng.Next 1 21 would also work fine I happen to prefer the version above..
filling a array with uniqe random numbers between 0-9 in c# http://stackoverflow.com/questions/10688044/filling-a-array-with-uniqe-random-numbers-between-0-9-in-c-sharp Random rng IList T list int n list.Count while n 1 n int k rng.Next n 1 T value list k list k list n list n value Usage var numbers..
C# producer/consumer http://stackoverflow.com/questions/1656404/c-sharp-producer-consumer Producing 0 i queue.Produce i Thread.Sleep rng.Next 1000 static void ConsumerJob Make sure we get a different.. Console.WriteLine t t t tConsuming 0 o Thread.Sleep rng.Next 1000 public class ProducerConsumer readonly object listLock..
Randomize a List<T> in C# http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp Random rng new Random int n list.Count while n 1 n int k rng.Next n 1 T value list k list k list n list n value Usage List Product..
Detailed Explanation of Variable Capture in Closures http://stackoverflow.com/questions/5438307/detailed-explanation-of-variable-capture-in-closures Random rng new Random int counter rng.Next 10 Console.WriteLine Initial value for counter 0 counter return.. new ActionHelper Random rng new Random helper.counter rng.Next 10 Console.WriteLine Initial value for counter 0 helper.counter..
An extension method on IEnumerable needed for shuffling http://stackoverflow.com/questions/5807128/an-extension-method-on-ienumerable-needed-for-shuffling buffer source.ToList for int i 0 i buffer.Count i int j rng.Next i buffer.Count yield return buffer j buffer j buffer i share..
Generating a Random Decimal in C# http://stackoverflow.com/questions/609501/generating-a-random-decimal-in-c-sharp int NextInt32 this Random rng unchecked int firstBits rng.Next 0 1 4 28 int lastBits rng.Next 0 1 28 return firstBits lastBits.. unchecked int firstBits rng.Next 0 1 4 28 int lastBits rng.Next 0 1 28 return firstBits lastBits public static decimal NextDecimal.. static decimal NextDecimal this Random rng byte scale byte rng.Next 29 bool sign rng.Next 2 1 return new decimal rng.NextInt32 ..
|