Author Topic: Really Wierd Bug - Schedule and getRandom inaccuracy  (Read 3087 times)

Thats... fairly clever.

We could always just beg Badspot to allow us more than 6 digits. He's going to need it eventually anyways.

Thats... fairly clever.

We could always just beg Badspot to allow us more than 6 digits. He's going to need it eventually anyways.
$Sim::Time

And
Resources by Ipquarx (9291)

Number Base Converter
http://forum.blockland.us/index.php?topic=182029.0

Integer Math Script
www.Ipquarx.com/Math.cs

Why are we limited to 6 digits anyway?

Lol at using the vector distance function.

It works, try it. echo(vectorDist(-988385297, 358726385));

EDIT: Oh wait, it does cause the answer to be truncated. Okay, try echo(vectorDist(358628675, 358726385));


It works, try it. echo(vectorDist(-988385297, 358726385));

EDIT: Oh wait, it does cause the answer to be truncated. Okay, try echo(vectorDist(358628675, 358726385));
why in hell are you using vectors for basic math

why in hell are you using vectors for basic math

Because it works for absurdly large numbers. Why aren't you using vectors for basic math? :D

He's right, and it's a brilliant idea.


The seed is used only once, that's why it's called a "seed". So the current time when the RNG context is created is the seed that is used and then it never changes (generally).
That depends on how the random function is used. I'm not sure of torque's syntaxes, but generally, I make Random number generators as local as possible
Example, in a function that asks for something random or needs random number generation, I do this:
Code: [Select]
Random rand = new Random((int)System.Time)
rand.nextInt(0,5);

I'm not sure how torque's random number generator works. I assume when you ask it, it sets its seed each time you ask for a new random number, unless this is not a random number generator badspot built in, but is pure torquescript, but again, I don't know torque's syntax.[/s]

EDIT: My assumptions appear false according to Destiny's lectures, disregard them, as he has more experience with this bugger of a language than I.
« Last Edit: December 30, 2012, 07:39:16 PM by Rykuta »

I'm not sure how torque's random number generator works. I assume when you ask it, it sets its seed each time you ask for a new random number
nope, it only changes when you call setRandomSeed(seed goes here);

I'm not sure how torque's random number generator works. I assume when you ask it, it sets its seed each time you ask for a new random number
That's not how a random number generator works. That's a (not random) hashing function. Like I said, the seed is used once and (usually) never touched against once it has been used to initialize the RNG.
That depends on how the random function is used. I'm not sure of torque's syntaxes, but generally, I make Random number generators as local as possible
Example, in a function that asks for something random or needs random number generation, I do this:
Code: [Select]
Random rand = new Random(gameTime.elapsedMilliSeconds)
rand.nextInt(0,5);

I'm not sure how torque's random number generator works. I assume when you ask it, it sets its seed each time you ask for a new random number, unless this is not a random number generator badspot built in, but is pure torquescript, but again, I don't know torque's syntax.
That is completely incorrect usage of a random number generator. The seed has to be unique per generator (generally using a unique time value such as time since the epoch, not a time delta like your code implies). If you were to use your code (say it's running in a time step callback in a game) then each user could possibly get the same seed (because in general, time deltas can be reliable on high-end hardware) and generate the same numbers which is not at all what you want in this case (again, assuming that your code wants unique numbers per user which it implies). The only case where sharing the seed of generators are really useful is cryptography or world generation and a few edge cases. That's not even considering the high amount of memory RNGs use. There should be a global RNG for the whole game (or a context, such as a world instance) to have predictable randomness (based on a unique seed if using time) and to keep memory use to a minimum.
« Last Edit: December 26, 2012, 02:33:58 AM by Destiny/Zack0Wack0 »

-snip-
I'm aware that using the computer's clock as the seed is the best way to go, however, I hadn't a clue what the syntax was at the time (Since the language I was using was C#), so I decided against using it, for fear of faqing it up. (In retrospect, a relativly useless fear, yet, OCD, what can I say.)

The point I was getting at, was simply to generate a random object each time it's used, and use a "time-esk" value for the seed.

Thank you for going into extreme depth about a situation explained in beginner computer science, It's clear you have knowledge in the subject, and I thank you for taking the time to explain it. However, please refrain from giving me lectures about stuff I'm already aware of. Sarcasm aside, I assume you saw ineffecient code, and as such, you had to fix it, happens to me all the time, but I seriously don't need the lecture.

Also off-topic, but, aren't you supposed to be dead? I was under the impression you died, rumours are stupid.
« Last Edit: December 30, 2012, 01:44:00 AM by Rykuta »

I think you're thinking of Mocheeze.

The point I was getting at, was simply to generate a random object each time it's used, and use a "time-esk" value for the seed.
Except as I explained above, that's not how you should be using it at all. You're not meant to create a new one each time it's used in scope, which is what your code implies unless it is global scope and seeing as this is C# I doubt it very much.
Thank you for going into extreme depth about a situation explained in beginner computer science, It's clear you have knowledge in the subject, and I thank you for taking the time to explain it. However, please refrain from giving me lectures about stuff I'm already aware of. Sarcasm aside, I assume you saw ineffecient code, and as such, you had to fix it, happens to me all the time, but I seriously don't need the lecture.
You obviously don't know this stuff correctly because you came in here assuming that PRNGs were seeded each cycle and posted an incorrect snippet of code that will give beginners the wrong idea. If you post in this category I am completely in my rights to school people just as everyone else is completely in their rights to do the same to me, this is how humans learn.