how to generator random numbers


i want to generat random numbers in c# how can i do it ?

the random numbers should at MIN be 1 digit long  and MAX 9 digits long

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaufmed 👽Commented:
You can only generate pseudo-random number, so you are aware. One of the choices you have to make, though, is whether you want a low-quality "random" number or a cryptographically random number. The latter is seemingly more random. The low quality random number can be made like this:

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

int value = rand.Next();

Open in new window

If you want cryptographically random, then you'll need to use a different class.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kensy11Author Commented:
thank i have one other small qaustion could you please help me

i like the outcome of this line of code to be like this

000000045  for example not just 45      so i used  {0:d9} but its not working do you know why ?

Console.WriteLine("Het nummer {0:d9} is een geldig studentnummer.", StudentNum");
kaufmed 👽Commented:
I'm not sure about that format specifier, but you can use "{0:000000000}" and it should give you that output.
kaufmed 👽Commented:

StudentNum will need to be a numeric type (e.g. int, decimal, double, etc.) in order for the padding to work the way you are expecting.
kensy11Author Commented:
thank you very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.