Hey, C#
Your random number generator is a fucking abysmal piece of shit. Whoever let the Random class get out the door w\o reliable pseudorandom number generation needs to be drug out into the street & shot. It took me half a fucking day to find a method that works.
Edited By Malcolm on 1261256191
Edited By Malcolm on 1261256191
Diogenes of Sinope: "It is not that I am mad, it is only that my head is different from yours."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
GORDON wrote:Pretty easy to make a "random" number generator based on the system clock, no matter what language you are using.
Nope. Not here. Trying to fuck w\ the DateTime class was pointless as well. That's what the Random class does by default anyhow. & it fucks up horribly. Had to break a class out of the secured crypto service package that pseudorandomly generates some bytes.
EDIT : I was generating dozens of random numbers per 100 nanoseconds. It just wasn't cutting it. I'd've needed time down to picoseconds or something.
Edited By Malcolm on 1261258025
Diogenes of Sinope: "It is not that I am mad, it is only that my head is different from yours."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
TheCatt wrote:Show me your code that wasn't working. Then, I'll tell you why it wasn't working.
I couldn't get random enough seeds. Tried ...
long longDiff = DateTime.Now.ToUniversalTime().Ticks -
new DateTime(1970, 1, 1).ToUniversalTime().Ticks()
Then forcibly cast it to an int, losing precision in the upper part, but maintaining randomness in the lower part.
int intDiff = (int)longDiff
Random rand = new Random(intDiff)
Then tried some trick w\ the Enumerable.Range() method, but that ended up being linear time, killing my run time overall.
Then tried this. Still not quick enough.
Finally found this. That worked.
Got my pseudorandomness going just fine now.
Edited By Malcolm on 1261262173
Diogenes of Sinope: "It is not that I am mad, it is only that my head is different from yours."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
From Macroshaft's own docs ...
I am unable to get to a finer granularity than 100s of nanoseconds w\o some form of cheating.
The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.)
Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calendar.
I am unable to get to a finer granularity than 100s of nanoseconds w\o some form of cheating.
Diogenes of Sinope: "It is not that I am mad, it is only that my head is different from yours."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Are you seeding it every time you call it? You should make the instance of Random a static or other variable that you can continue to call, pulling out numbers, without reseeding, using Random.Next().
The whole point of the Random class is that you seed it once then call it multiple times to get a stream of numbers.
I just generated 20,000 random numbers in less than a second, which means nano-second level. It worked just fine.
[/color]
Edited By TheCatt on 1261268331
The whole point of the Random class is that you seed it once then call it multiple times to get a stream of numbers.
I just generated 20,000 random numbers in less than a second, which means nano-second level. It worked just fine.
Code: Select all
private void getRandoms()
{
List<int> newList = new List<int>();
Random r = new Random();
DateTime Start;
DateTime End;
Start = DateTime.Now;
for (int i = 0; i < 20000; i++)
{
newList.Add(r.Next(100));
}
End = DateTime.Now;
Edited By TheCatt on 1261268331
It's not me, it's someone else.
The dude I'm programming this shyte w\ supposedly had some info to the effect of ... after the first generation, C#'s Random class fails to provide decent randomness.
Arguing w\ him was even more of an uphill fight than finding a decent algorithm.
Arguing w\ him was even more of an uphill fight than finding a decent algorithm.
Diogenes of Sinope: "It is not that I am mad, it is only that my head is different from yours."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
It's not what I'm using them for that was causing issues ... alright, I guess I suppose it is. I'm essentially using a simulator to guess at weights in a mathematical system. I want shyte as "random" as possible so I can get the least tainted results.TheCatt wrote:What are you using the #s for? I mean, yea, it's not the best number generator in the world, but it's fine for anything but cryptography.
Working on a game, need to assign proper costs for each stat. I've got a fight simulator that runs some sets of input 100x each. I bet I need a few hundred random #s per fight. Was running thousands of fights serially, lots of Randoms() getting created, all giving me identical results, skewing my results like a biazniatch. I really want these stats as closed to balanced as possible, so I'm being extremely picky about the generator.
Diogenes of Sinope: "It is not that I am mad, it is only that my head is different from yours."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Damn, I actually want one now.TheCatt wrote:Here you go.
Diogenes of Sinope: "It is not that I am mad, it is only that my head is different from yours."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
Arnold Judas Rimmer, BSC, SSC: "Better dead than smeg."
I have absolutely no need for it, and I want it too.Malcolm wrote:Damn, I actually want one now.TheCatt wrote:Here you go.
"... and then I was forced to walk the Trail of Tears." - Elizabeth Warren