enum choose Random :)

Got this

 enum State

  void Start()
         //Wanna make this state choose a random State from State. :P So somethimes its left     other times its right....
        state = State.Left;

Well the two solutions here will work in your case, but since enums are not restricted to sequential values here's a general approach (C#):

I just wrote a little generic helper function that will select a random enum member.

static T GetRandomEnum<T>()
    System.Array A = System.Enum.GetValues(typeof(T));
    T V = (T)A.GetValue(UnityEngine.Random.Range(0,A.Length));
    return V;

And here's a little example:

enum MyEnum
    Dog = 1,
    Cat = 2,
    Cow = 502,
    Bird = 621

MyEnum choice = GetRandomEnum<MyEnum>();

And in your case you could do:

state = GetRandomEnum<State>();

Since it's just two choices:

state = Random.value < .5 ? State.Left : State.Right;

Give this a bash.

EDIT: Added + 1 to the Max parameter of Random.Range(), as per Peter's comment.

state = Random.Range((int)State.Left, (int)State.Right + 1);

Thx all :) DaveA answer did the job..