This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Extension methods for the <see cref="System.Random"/> class. | |
/// </summary> | |
public static class RandomExtensions | |
{ | |
/// <summary> | |
/// Returns a random unsigned ulong | |
/// </summary> | |
public static UInt64 NextUInt64(this Random random) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Sieve of Eratosthene, C# implementation by George Corkery (github.com/gpc91) | |
* Something made for fun, feel free to use without attribution | |
* For more about the Sieve of Eratosthene, see this wikipedia page: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
*/ | |
using System; | |
using System.Collections.Generic; | |
class Eratosthene | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string NumberToBinary<T>(T val) where T : notnull, IConvertible | |
{ | |
try | |
{ | |
long value = val.ToInt64(null); | |
int size = System.Runtime.InteropServices.Marshal.SizeOf(default(T)); | |
return BitConverter.IsLittleEndian ? | |
Convert.ToString(value, 2).PadLeft(size * 8, '0') : | |
Convert.ToString(value, 2).PadRight(size * 8, '0'); | |
} |