private static readonly Random oti = new Random( Guid.NewGuid().ToByteArray().Sum( b => b * b.GetHashCode() ) ); private static readonly ReaderWriterLockSlim otia = new ReaderWriterLockSlim( LockRecursionPolicy.SupportsRecursion ); public static T RandEnum() { if ( !typeof( T ).IsEnum ) { return default( T ); } var names = Enum.GetNames( typeof( T ) ); try { otia.EnterWriteLock(); return ( T )Enum.Parse( typeof( T ), names[ oti.Next( 0, names.Length ) ] ); } finally { otia.ExitWriteLock(); } }
Sunday, October 31, 2010
Random Enum in C#
I wrote this because.. well.. I wanted to see how well it would work.. 8D
Thursday, September 2, 2010
DateTime.Now in C# 4.0 Causes Dynamic Memory Allocations
Darnit. My favorite language too..
Saturday, August 28, 2010
Practical Programming: Hidden Talents
Found this blog that has a few useful tips such as SecureString, MemoryFailPoint, and System.Media.
Subscribe to:
Posts (Atom)