|
I think you get the same Ticks twice.
Have you tried re-using the random number generator?
for(int i = 0; i < rounds; i++){
System.Random randomNumberGenerator = new System.Random((int) DateTime.Now.Ticks); bool firstPlayersChoice = GetRandomBool(randomNumberGenerator);
bool secondPlayersChoice = GetRandomBool(randomNumberGenerator);
}
public static bool GetRandomBool(System.Random randomNumberGenerator){
int randomNumber = randomNumberGenerator.Next();
if(randomNumber % 2 == 1)
{
return true;
}
else
{
return false;
}
}
____________________________________
There is no proof for this sentence.
|
|
|
|
|
I think it's a better idea to reuse more times the random generated sequence,
see my posting [^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for the reply, Coco. Unfortunately, I have some constraints - I cannot modify GetRandomBool's signature. You see, it's a method in a different assembly that is called using a superclass reference. I've updated my post to reflect the constraints.
I'd appreciate any help.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
You should NOT restart the number generator sequence each time your GetRandomBool is called.
I suggest the following changes:
System.Random randomNumberGenerator = new System.Random((int) DateTime.Now.Ticks);
for(int i = 0; i < rounds; i++)
{
bool firstPlayersChoice = GetRandomBool(randomNumberGenerator);
bool secondPlayersChoice = GetRandomBool(randomNumberGenerator);
}
...
public static bool GetRandomBool(System.Random rg)
{
int randomNumber = rg.Next();
if(randomNumber % 2 == 1)
{
return true;
}
else
{
return false;
}
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for the reply, mate. Unfortunately, I have some constraints. Please see my original post (I've updated it). Would appreciate assistance.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
You're going to have to introduce a waitstate into your call then. Every call to GetRandomBool() made before the system ticks will return the same value since you're reinitializing the RNG to the same starting value. IIRC the tick is a legacy timer that only updates ~18x per second. The highest resolution timer you can get will report in milliseconds but only actually updates every 10-30ms (depends on machine, may vary more with ones I didn't test on). If you can't change GetRandomBool() and need more than 18 returns per second you're SOL.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
If your constraint applies only to the function signature then modifty its body as follows:
static System.Random _randomNumberGenerator = new System.Random((int)DateTime.Now.Ticks);
public static bool GetRandomBool()
{
int randomNumber = _randomNumberGenerator.Next();
if(randomNumber % 2 == 1)
{
return true;
}
else
{
return false;
}
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Your solution is so simple, it's beautiful. 5'd.
You'll get your mention in the upcoming article, CPallini.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
Vikram A Punathambekar wrote: Your solution is so simple, it's beautiful. 5'd.
Thanks.
Vikram A Punathambekar wrote: You'll get your mention in the upcoming article, CPallini.
Thanks again.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
The Random object initialises itself with a value from the System Time so most of the time you're going to get the same value. occasionally the clock will tick over between calls. This seems to be the behaviour you're getting.
If i'm using random I tend to add it as an instance variable or as a public static variable of another class and call getNext() without resetting it.
I found this problem out the hard way and had to ask the good people on CP at the time.
Russ
|
|
|
|
|
Thanks for the reply, Russell. Unfortunately, I have some constraints. Please see my original post (I've updated it). I'd appreciate your assistance.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
As there's no chance to alter GetRandomBool(), you might insert a delay:
bool firstPlayersChoice = GetRandomBool();
Thread.Sleep(1);
bool secondPlayersChoice = GetRandomBool();
Any questions about the program being slow can be redirected to the author of GetRandomBool().
____________________________________
There is no proof for this sentence.
|
|
|
|
|
Corinna John wrote: Any questions about the program being slow can be redirected to the author of GetRandomBool().
Since that is yours truly, I changed it as CPallini suggested.
Thanks for your help, though!
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
I have seen your constraint!
Whoever has written GetRandomBool has written it incorrectly for rapid sequential calls. The random number generator must be reused instead of recreated for each call.
Sorry buddy you really are SOL.
|
|
|
|
|
J4amieC wrote: Whoever has written GetRandomBool has written it incorrectly for rapid sequential calls.
That would be, uh, me. I changed it now - see my reply to CPallini.
Cheers,
Vikram.
The cold will freeze our stares
We won't care...
|
|
|
|
|
If you have the source for the class containing GetRandomBool you could create a static private Random object and call that from GetRandomBool instead. I doubt the overhead of having a random object hanging about is too huge, but you'd need to check.
|
|
|
|
|
hi,
i want to get the total time of the mp3 file. how i get? pls ans me
thank u
senthil
|
|
|
|
|
Hi.
Try to look here: http://www.un4seen.com/
|
|
|
|
|
I have alredy added a DataSet name Publications where I have add three tables.
Table(0) is Query_Volume_VolumeLessons
Table(1) is Query_Volume_Sectos
Table(2) is Query_Volume_Themes
Also put data on Table(0) from SQL SERVER DataBase
Now I need to put data to Table(1) from DataSet Table(0) using a sql query.
Question is?
Do I need any connectionStrings? or should I put the query Insert INTO Table(0) from Table(1) if yes how can I execuite this command in VS code.
Please help me Im suffering a lot
Thanks
Sarfarj Ahmed
|
|
|
|
|
i think if u want to fill table with sql query then it will require connection string,because u can execute query through command object which require connection string.
rahul
|
|
|
|
|
Is their any other way that I can put data from DataSet.Tables(0) to DataSet.Tables.(1)
Sarfarj Ahmed
|
|
|
|
|
Hi,
I need to know who is the splitContainer which contains a determined panel.
Imagine that i create a event that is triggered when i click a panel1 or panel2 of a splitContainer.
How can i know, who is the splitContainer from the Panel click?
Thx,
Nuno
|
|
|
|
|
Try the Parent property.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
The SplitterPanel doesnt have a Parent propertie.
|
|
|
|
|
According to MSDN its there (SplitterPanel.Parent Property[^]) and should return what you want. I do not know why it is not intended to be used directly from code, but probably that's why it is not shown to you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|