 |
|
 |
Hi,
Neat piece of code and thanks for adding it to Code Project!
I've been playing around with cycle counts based on time formats and came across your article. I've noticed that 1 millisecond or 1000 cycles, may result in duplicated result sets and wanted to look further into this. I looked into your method and created a quick console app to test this out and sure enough when I increased to 10000 cycles this problem was easily overcome and thought it worth sharing for prosperity
using System;
using System.Collections.Generic;
using System.Text;
namespace random1_6
{
class Program
{
static void Main(string[] args)
{
// number of results required?
int required = 4;
for (int z = 0; z < required; z++)
{
// time needs to be above 1000 cycles or dupes will occur!
int c = 10000;
// number array holder
int[] numb = new int[c];
DateTime dt = new DateTime();
dt = DateTime.Now;
Random rnd = new Random(dt.Millisecond);
for (int i = 0; i < c; i++)
{
// change 45 for required number system. ie; 46 numbers
numb[i] = rnd.Next(1, 45);
}
Array.Sort(numb);
int k = 0;
int j = 0;
int[] length = new int[50];
int[] result = new int[50];
for (int i = 0; i < c - 1; i++)
{
if (numb[i] == numb[i + 1])
{
result[k] = numb[i];
length[k] = j += 1;
}
else
{
k += 1;
j = 0;
}
}
Array.Sort(length, result);
Console.WriteLine(result[49] + " "
+ result[48] + " "
+ result[47] + " "
+ result[46] + " "
+ result[45] + " "
+ result[44]);
}
Console.Read();
}
}
}
|
|
|
|
 |
|
 |
Hi
May I use your lotto algoritm?
Thanks
Husso
|
|
|
|
 |
|
 |
from,
-= aLbert =-
|
|
|
|
 |
|
 |
Just starting out with c++, and need to find out how to place a random number into an array of 26 characters, only changing those character that are indexed by the random number...
The range of the random nuber is between 1 and 24, I can generate the random number OK but I just want to place the end number into the array not all of the random number i.e 1 to 24..
|
|
|
|
 |
|
 |
This is a general programming question, in a different language to the article, and should be in the C++ forum, where lots of people can answer it.
To be honest I cannot even understand exactly what you want to do. Are you allowed to use vector, or is this a homework question with set parameters ?
<edit>I realised you have an array of 26 characters, therefore vector would be useless anyhow. What's the problem exactly ? You have the number and you know the index, so where is it goin wrong ? Is it an array of chars, or of numbers ? What do you want to change it to ? </edit>
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
 |
|
|
 |
|
 |
It only picks numbers from 1-49, if your lottery has more numbers...change it. It will not pick winning numbers all the time, it just tells you which numbers were randomly selected the most. It's not the best program ever written, just for fun.
...Zack...
|
|
|
|
 |
|
 |
Well, did you win anything by using this program?
|
|
|
|
 |
|
 |
hell nooooooooo never ever
|
|
|
|
 |
|
 |
I feel so cheated!
Old Macdonald had a farm and I had it after
I had the cows, I had the pigs
I'm an animal shafter
|
|
|
|
 |
|
 |
I think it's incompatible with certain lottery versions.
cheers,
Chris Maunder
|
|
|
|
 |
|
 |
Ok... I´ll use the program and bet in the lotery here in Brazil. If I win I´ll buy a VS.NET copy from CP.
Mauricio Ritter - Brazil
Sonorking now: 100.13560 MRitter
|
|
|
|
 |
|
 |
LOL !!! So you're saying if I run it, I'll have the numbers for a lottery somewhere in the world, but not necessarily the one I enter ? So the NEW lottery is picking the right one ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
 |
|
 |
::snickers::
Yea, lottery number picking is NOT a random process... its based on sound scientific fundamentals based on fractal algorithms to the hypercube parallel math operator and implemented with a gourand GOF pattern.
|
|
|
|
 |