How do I create an application involving random numbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Newsgroup

I'm new in C#, and I was wanting to create a console application involving generating 100 random
numbers between 0 and 1000. After running that method, I want to write a method to test if
the number is an even or odd number. After that I need to display in the console the smallest,
largest, number of odds, and number of evens. Any help would be appreciated

Thanks in advance.
 
This posting is provided "AS IS" with no warranties, and confers no rights

Hi ,

I have a link that gives the code to generate Random numbers in C#.net .
Hope it helps . Pls do not forget to see the SEE ALSO section at the
bottom of the Web Page


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemrandomclasssampletopic.asp

For even number validation :
This is very big artilce . Hope it helps . I m not very sure . Go
through that fully.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
/ASPNet-ValidateASPNetServerControls.asp

Regards,
Venkat.
 
Hi, Zeb

This sounds like a homework assignment, but here goes.
To create random numbers use the Random class and create a Random object..
Use its next method with a parameter specifying the highest random number
(+1).

To detect odd or even numbers you can use bitwise AND with the number 1.
If the result is 1 the number is odd.

To detect highest and lowest number you would need to check all numbers
and compare them. I'm not sure what is faster of if(x < y) or
Math.Max/Min(x, y).


Happy coding!
Morten Wennevik [C# MVP]
 
Back
Top