I'm using C# in .NET Framework 3.5 and am trying to generate a random integer by 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 alright, but I'm getting the error that System.Random isn't a valid namespace, but I'm pretty sure it is...
Anybody know what's the problem or some other method I should be using to generate a random integer within a range?
Random
is a class in the System
namespace. Change the first line to just using System;
and you should be good to go.
The Random class is a part of the System
namespace, not System.Random
. You can reference the type directly using the namespace though:
System.Random rnd = new System.Random();
Or..
using System;
Random rnd = new Random();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With