System.Random.NextInt64()

Here are the examples of the csharp api System.Random.NextInt64() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : RandomExtensions.cs
with MIT License
from XionWin

public static long NextInt64(this System.Random rnd)
        {
            var buffer = new byte[8];

            rnd.NextBytes(buffer);
            var candidate = BitConverter.ToInt64(buffer, 0);

            // wrap negative numbers around, mapping every negative number to a distinct nonnegative number
            // MinValue -> 0, -1 -> MaxValue
            candidate &= long.MaxValue;

            // skip candidate if it is MaxValue. Recursive since rare.
            return (candidate == long.MaxValue) ? rnd.NextInt64() : candidate;
        }