473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How do I create an application involving random numbers

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.
Nov 16 '05 #1
2 2376

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/de...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/de...us/dnaspp/html
/ASPNet-ValidateASPNetServerControls.asp

Regards,
Venkat.

Nov 16 '05 #2
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]
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I...
25
by: JNY | last post by:
I am using random to generate random numbers, thus: int x,y; for (y = 0;y < 5;y++) { x = random(50); cout << x; }
21
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to...
13
by: quickcur | last post by:
Suppose I have a function rand() that can generate one integer random number between 0 and 100. Suppose also rand() is very expensive. What is the fastest way to generate 10 different random number...
23
by: Alvin | last post by:
Well, I'm developing a Tetris game in SDL, but when it comes to deciding the next block, I'm stuck. It's random, but when I try something like seeding the randomizer with the time, it won't update...
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
1
by: thaond | last post by:
Hi ! I want to create a Random number be in the Around, but not same the numbers created before ! Exam : My around : 0000,......,9999 Random number was created : 1234, 2134, 0001, 9998...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.