Extension method to randomize an enum?

I would like to be able to randomize the value of an instance of an enum with a simple extension method, but what I created doesn't seem to have any effect yet.

public static void Randomize(this Enum theEnum) { System.Array A = System.Enum.GetValues(theEnum.GetType()); theEnum = (System.Enum) A.GetValue(UnityEngine.Random.Range(0,A.Length)) as System.Enum; } 

What am I missing? Thanks if anyone has knowledge of this.

by Ryahes via /r/csharp

Leave a Reply