473,394 Members | 2,020 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,394 software developers and data experts.

lotto 'style' random number generator with duplicate checking in C#

My first app in 30 years ... how logically bad is it?
Lame lotto number generator but found it interesting enough to motivate me to code again ... lol. I would think there is a better way to check for duplicates and an easier way to display each 'ball' number into a different label. Thanks to any who might spend a moment to look this over
Expand|Select|Wrap|Line Numbers
  1.             // Initialize variable to point to each number in the array
  2.             int m = 0;
  3.  
  4.             // Loop until 5 random numbers have been generated and assigned to the array
  5.             for (int i = 0; i < mmar.Length; i++)
  6.             {
  7.                 // create arrays to utilize higher probablistic ranges for each ball
  8.                 int[] y = new int[5] { 1, 3, 8, 18, 30 };
  9.                 int[] z = new int[5] { 21, 31, 52, 63, 71 };
  10.                 // use the for loop's initialized variable to change random range
  11.                 mmnum = mmball.Next(y[i], z[i]);
  12.                 // Loop to ensure each number is unique
  13.                 for (int j = 0; j < mmar.Length; j++)
  14.                 {
  15.                     // check the number of ball for duplicates
  16.                     if(mmnum == mmar[j])
  17.                     {
  18.                         // if not unique create new ball
  19.                         mmnum = mmball.Next(1, 71);
  20.                         // re-initialize to ensure new ball number is unique
  21.                         j = 0;
  22.                     }
  23.                 }
  24.                 // put the ball number into our array
  25.                 mmar[m] = mmnum;
  26.                 // change to new array slot
  27.                 m++;
  28.             }
  29.  
  30.             // Sort the numbers in the array before displaying them
  31.             Array.Sort(mmar);
  32.             // OLD ... START Place lotto numbers on screen
  33.             num1mm.Text = mmar[0].ToString();
  34.             num2mm.Text = mmar[1].ToString();
  35.             num3mm.Text = mmar[2].ToString();
  36.             num4mm.Text = mmar[3].ToString();
  37.             num5mm.Text = mmar[4].ToString();
  38.  
Jan 22 '20 #1
0 2446

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Aaron | last post by:
I need some help writing this function the function returns a list of random non-duplicate integers in a string, 1 parameter indicating the maximum range. string randGen(int maxRange) ...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
9
by: L33VaNcL33F | last post by:
I like to make a javascript that generate random number from the range number within : (10016486 and 99999985). the number always + 22423 that begin from 10016486 and end at 99999985 Example...
16
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers...
4
by: Lexicon | last post by:
Hello; Does anyone know a 64-bit integer generator for 32-bit machines that use long long or __int64 etc ?
3
AccessQuestion
by: AccessQuestion | last post by:
So just a quick question; more out of curiosity than anything. I have a form in which I pop a random number into a text box. Eventually that number will be placed by a user using a scale, but I...
3
by: MattBrady | last post by:
Ok, so I just started learning python and I've made a simple random number generator already but now I want the user to define the range in which the number can be generated. This is what I have so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.