<p>Could someone please point me toward a cleaner method to generate a random enum member. This works but seems ugly.</p>

<p>Thanks!</p>

<pre><code>public T RandomEnum&lt;T&gt;()
{
  string[] items = Enum.GetNames(typeof( T ));
  Random r = new Random();
  string e = items[r.Next(0, items.Length - 1)];
  return (T)Enum.Parse(typeof (T), e, true);
}
</code></pre>

```
```
public T RandomEnum<T>()
{ 
  T[] values = (T[]) Enum.GetValues(typeof(T));
  return values[new Random().Next(0,values.Length)];
}
```
```
Thanks to @[Marc Gravell] for ponting out that the max in Random.Next(min,max) is exclusive.