# Generate random number in Unity without class ambiguity

I have a problem in Unity (C#) where I would like to create a random number. I wanted to use System.Random (reference: using System) but Unity complains that it's ambiguous to their own UnityEngine.Random. I can not specify the reference (using System.Random) as random is not a namespace. How do I specify that I want to use the system random and not the Unity one?

• It seems to me that the title of the question doesn't really reflect the question. The easiest way to do what the tile says is simply use Unity's RNG, which may be generally good advice anyway. Of course if you're not using anything from the UnityEngine namespace (unlikely) you could just omit that using statement. – Zeus Aug 6 at 16:58

You could specify the namespace explicitly:

System.Random random = new System.Random(seed);
random.Next();


You can use a using alias directive to give System.Random a new name as well:

using Rng = System.Random;

• using Random = System.Random; is fine too – trollingchar Aug 4 at 17:13
• using LiterallyAnyOldString = System.Random; is also fine, you can use anything you want, the same rules apply as for variables – MindSwipe Aug 5 at 9:23
• @MindSwipe I think trollingchar's point was that Random is fine and unambiguous, even in contexts where UnityEngine.Random is available. – Alexander Aug 5 at 22:48