Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: FUBAR-BDHR on November 16, 2008, 02:08:45 am

Title: Rand-multiple take 3
Post by: FUBAR-BDHR on November 16, 2008, 02:08:45 am
Think I just found a new quark with rand-multiple (like there weren't enough of them already).   It's acting like there is a finite range it will return from no matter how big the range you specify is.  Basically the range is 800000 but it will only return values up to about 30000.  Not sure what the max is but I never saw a result bigger that that. 

Is there a limit to the range or value it will return? 
Title: Re: Rand-multiple take 3
Post by: Shade on November 16, 2008, 02:26:22 am
My guess then would be that the max is 32768, or 2^15. That would leave on bit free for negative numbers when using 16 bits to store the numbers. Would have to look at the code to verify that, though.
Title: Re: Rand-multiple take 3
Post by: FUBAR-BDHR on November 17, 2008, 12:05:24 am
Well I did try -400000 to 400000 before I tried 0 to 800000 but never got a value above -370000.  If you can confirm that there is a maximum range can you add that to the description for the sexp? 
Title: Re: Rand-multiple take 3
Post by: karajorma on November 17, 2008, 03:00:07 am
As far as I can see the code is all ints. Not a single short in there so I can't see why it would be limiting itself to 16-bit values. Stick it in Mantis and assign it to me.
Title: Re: Rand-multiple take 3
Post by: Vidmaster on November 17, 2008, 08:39:02 am
I would be interested more in the question, why random doesn't behave like it should.
Fubar knows the problem, since he is working on the mission in question.

Multiple Randoms in the same event seem to produce very similar results. Not exact results but close ones.
Title: Re: Rand-multiple take 3
Post by: FUBAR-BDHR on November 17, 2008, 12:53:23 pm
@Vid:  Look at the problem I described.  It's happening because it's only returning < 4% of the values it should be.

@Kara:  http://scp.indiegames.us/mantis/view.php?id=1823  I'll get you the one example of this one in a few hours.  The other might take a bit longer but we had a discussion about it on here before.   I just need to dig up that test mission which could be named anything and be in any of 20 locations. 

Found the thread anyway:  http://www.hard-light.net/forums/index.php/topic,53198.0.html  Can't believe the HLP search actually worked.
Title: Re: Rand-multiple take 3
Post by: karajorma on November 18, 2008, 04:10:38 pm
Okay. I know what's causing this. Solving it might be a whole different matter though. I'm going to post on the internal and see if the other coders have any ideas.
Title: Re: Rand-multiple take 3
Post by: FUBAR-BDHR on November 18, 2008, 04:31:45 pm
Remember even though I found the bug it's all Vid's fault since it was his mission.   :D
Title: Re: Rand-multiple take 3
Post by: Vidmaster on November 19, 2008, 01:40:56 am
isn't this weird?

If I encounter problems with an advanced effect I want to create, I always ask FUB (and done this frequently in the past). And in almost every case so far, it doesn't work because some kind of sexp bug.  ;)
Title: Re: Rand-multiple take 3
Post by: karajorma on November 19, 2008, 01:51:46 am
Well to be fair this isn't really so much the fault of the SCP or :v: so much as the idiotic way the random function works in C. :)

What's rather scary is recently most of the bugs I've investigated have resulted in me opening a rather big can of worms. This week has actually been rather calm in comparison. :)
Title: Re: Rand-multiple take 3
Post by: FUBAR-BDHR on November 19, 2008, 01:04:26 pm
/me Tosses Kara a fishing rod

Well since you have all those cans of worms might as well put them to good use.   :D