Random, and it's non-randomness
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
locke

EDIT: NEVERMIND... I've realized that Random is indeed producing random numbers. My code, however, is not. Sorry about that.

So I did a search, and there are (of course) quite a few posts on the well-known Random() bug. Now, correct me if I'm wrong, but wasn't it fixed a while back?

Turns out I'm getting a suspiciously similar result from a bunch of random number generations, and I'm wondering if it's not fixed.

Err... so was it fixed?

Thanks.

-l

Posted on 2005-03-02 14:34:44 (last edited on 2005-03-02 14:55:03)

vecna

Random, as far as I can tell 'works as intended' now.
What that means is as follows.

If I do SetRandSeed(1) and call Random() 50 times, I will get the same 50 numbers each time. That's intended.

If I do SetRandSeed(0), then the seed will be set to a 'random' value based on the system time - you should get different values each time.

As far as I know, the random seed is initialized randomly when verge.exe starts up. But I'm at work and dont have the code handy.

Edit: any non-zero seed will be considered a 'fixed' seed. Passing 0 specifically tells it to use a timer-based seed.

Posted on 2005-03-02 14:55:39 (last edited on 2005-03-02 14:56:48)

gannon

I think there still is a crash bug when you pass in a negative number in the second argument and a larger number in the first argument. It doesn't always crash sometimes it returns junk,

Posted on 2005-03-02 15:26:48

locke

Quote:Originally posted by vecna

Random, as far as I can tell 'works as intended' now.
What that means is as follows.

If I do SetRandSeed(1) and call Random() 50 times, I will get the same 50 numbers each time. That's intended.

If I do SetRandSeed(0), then the seed will be set to a 'random' value based on the system time - you should get different values each time.

As far as I know, the random seed is initialized randomly when verge.exe starts up. But I'm at work and dont have the code handy.

Edit: any non-zero seed will be considered a 'fixed' seed. Passing 0 specifically tells it to use a timer-based seed.


Yep. It's working perfectly. I usually SetRandSeed(systemtime), as I am now, and it works like a champ. That explanation should go in the Docs for SetRandSeed, btw.

My problem was a loop that kept resetting what I wanted to make random. Bugger of a bug, I must say.

Thanks for responding, V.

-l

Posted on 2005-03-02 15:30:28

RageCage

Quote:Originally posted by gannon

I think there still is a crash bug when you pass in a negative number in the second argument and a larger number in the first argument. It doesn't always crash sometimes it returns junk,


Random() is meant to always have the first number be less than the second.

Posted on 2005-03-02 21:46:46

gannon

you can't assure that in all cases :P
but it is easy to make a wrapper :)

Posted on 2005-03-02 22:47:14

Overkill


void my_random (int a, int b)
{
if (a > b)
{
return random (b, a);
}
if (a == b)
{
return a;
}
return random (a, b);
}

Posted on 2005-03-04 06:52:51

Zip

Your adding all these helpful bits of code to the vault, right, ovk? And er... with better function names too...

Zip

Posted on 2005-03-05 06:07:11


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.