Using System.Random

I am using C # in the .NET Framework 3.5 and trying to create a random integer using Random (). My code is here:

using System.Random;

int randomNumber;
Random RNG = new Random();
randomNumber = RNG.Next(1,10);

I think everything should be fine, but I get an error that System.Random is not a valid namespace, but I'm sure it is ...

Does anyone know which problem or some other method I should use to generate a random integer within a range?

+5
source share
4 answers

Randomis a class in the namespace System. Change the first line only to using System;and you should be good to go.

+10
source

Random System, System.Random. , :

System.Random rnd = new System.Random();

..

using System;

Random rnd = new Random();
+6

You need to use System-Namespace

using System;

int randomNumber;
Random RNG = new Random();
randomNumber = RNG.Next(1,10);
+4
source

You do not need a using statement. Your use statement is not valid.

Random is a class in the System namespace. Just use

using System;

instead using System.Random;

+3
source

All Articles