Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: IPAndrews on July 14, 2005, 04:57:10 am

Title: rand & rand-multiple
Post by: IPAndrews on July 14, 2005, 04:57:10 am
In which build was the "rand" SEXP first change and in which subsequent build was "rand-multiple" introduced to do what "rand" used to do?
Title: rand & rand-multiple
Post by: phreak on July 14, 2005, 10:24:20 am
rand-multiple was introduced on 1/26/05

rand was "fixed" on 12/23/02
Title: rand & rand-multiple
Post by: Goober5000 on July 14, 2005, 06:09:14 pm
Quote
Originally posted by PhReAk
rand was "fixed" on 12/23/02
Actually, that was when rand was "broken".  It was restored to its original code when rand-multiple was introduced.
Title: rand & rand-multiple
Post by: phreak on July 15, 2005, 10:53:43 pm
hence the quotes.

Code: [Select]
* Revision 2.14  2002/12/23 05:41:08  Goober5000
 * Bah - Andsager is a moron. :) I see no reason why rand shouldn't work
 * multiple times.  It's been fixed thus.
 * --Goober5000
Title: rand & rand-multiple
Post by: Goober5000 on July 15, 2005, 11:03:53 pm
Oh okay, I gotcha.

I deeply regret calling a :v: programmer a moron. :(
Title: rand & rand-multiple
Post by: karajorma on July 16, 2005, 03:39:18 am
Was there ever anyything that the fix to rand ever broke?

It's not an often used SEXP anyway and you have to be using it in a repeating event to notice anything that Goober ever did to it.
Title: rand & rand-multiple
Post by: Goober5000 on July 16, 2005, 05:46:51 am
It's more subtle than that, and it doesn't require a repeating event.  Suppose you have an event that combines both "rand" and another sexp using "and".  The code must continually evaluate the two conditions until both are true.

The original implementation of "rand" had the sexp short-circuit its evaluation by replacing itself with the chosen random value.  In effect, the random number was only picked once, and it remained consistent for every evaluation of the sexp.  My original change caused "rand" to pick a new random number every time the sexp was evaluated.  (This is what "rand-multiple" does now.)

I can't really think of an example to illustrate the result of this, but you can think of it as a sort of quantum uncertainty.  The value of "rand" is unknown until it is locked in place when both halves of the "and" sexp become true at the same time.  I forget the exact situation which clued me in to this difference, but it definitely exists as evidenced by the fact that TBP noticed it. :)

As an aside, "rand-multiple" is probably not the best name for the new sexp but it was the best I could think of at the time.  Do you have any suggestions?  "Quantum-rand", maybe? ;)
Title: rand & rand-multiple
Post by: karajorma on July 16, 2005, 07:00:24 am
I see. What happens when you use Rand with every-time though? I imagine that in that case it would re-evaluate itself right?
Title: rand & rand-multiple
Post by: Goober5000 on July 16, 2005, 07:50:44 am
Probably.

That might be a better way of illustrating the difference between when and every-time than with key-pressed. :)
Title: rand & rand-multiple
Post by: karajorma on July 16, 2005, 11:56:27 am
Yeah. I'll try that out in a little bit.
Title: rand & rand-multiple
Post by: Roanoke on July 16, 2005, 03:26:35 pm
*head starts spinning*
Title: rand & rand-multiple
Post by: karajorma on July 16, 2005, 05:18:01 pm
It's pretty simple. If you really want an explaination I'm happy to type one up for you :)

What's confusing you?
Title: rand & rand-multiple
Post by: Roanoke on July 18, 2005, 04:19:32 am
Nah, don't worry about it. ;)
Title: rand & rand-multiple
Post by: karajorma on July 18, 2005, 07:51:25 am
Fair enough. I'll be adding explainations for this sort of thing to my FAQ sooner or later anyway :D