Search In
• More options...
Find results that contain...
Find results in...

# [SOLVED ACS weird] random() not being random

## Recommended Posts

Consider this script, activated when shooting a linedef:

```script 103 ( int blah ) {
int	n0, n1;

SetResultValue(0);
n0 = random(0,3);
print(s:"n0 = ",d:n0 );
...
}```
So if you use a weapon that shoots multiple pellets (shotgun, ssg), you'll get multiple activations (per pellet) with each discharge of your weapon. I've observed that n0 however isn't random, but always the same number for each pellet that hits. Each discharge results in a different number.

So, for one discharge:
```n0 = 1
n0 = 1
n0 = 1
n0 = 1```
But...
```script 103 ( int blah ) {
int	n0, n1;

SetResultValue(0);
n0 = random(0,3);
n1 = random(0,3);
print(s:"n0 = ",d:n0,s:" n1 = ",d:n1 );
...
}```
Now BOTH n0 and n1 have different numbers for each activation per multiple-pellet discharge.

So, for one discharge:
```n0 = 1 n1 = 3
n0 = 2 n1 = 0
n0 = 0 n1 = 2
n0 = 1 n1 = 1```
Why isn't the n0 = random() in the first code example random like the n0 = random() in the second example?

Can you make a minimal test map for this with both versions as different scripts? I need to single step them in the debugger, as this is either a problem with the interpreter itself, or with the print() function.

Already shared this with you by email, but just got Dropbox to behave again as well.

1. In your start room, walk over the marble arrow and a door will come down. But not quite all the way down, despite target being 'floor'. The switch in front of it has the same action, except instead of WR it is SR. Notice how this will work correctly and set the ceiling to floor level. The actual wrong height of the lowered pillar depends on the build. The switch to your left resets it. Also, notice how the WR trigger raises the level of the pillar ceiling again if you had lowered it before with the switch version. Last version that works correctly: drdteam 550.

Next room is divided into a startan part (with stuff that works correctly) and a marble part showcasing bugs.

2. Shoot the 'imps'. It will print the scripts that are activated. It should be ' blahscript', 100, 101. The 'marble imp' uses a acs_executealways instead of acs_execute for script 101; and you'll see this one does not print its text when shot.

3. The switches on either side. Equip a shotgun and shoot. Due to setting SetResultValue(0) each pellet will activate the script. One of them uses 2 random(0,3) calls, notice how n0 and n1 gets different (random) numbers. The other one only uses one random(0.3) call... notice how that value is always the same.

Fixed all these.

1. This was undefined behavior. In your case it went halfway, in mine it kept sinking into the floor. It might have remained undetected for a long time.

2. ACS_ExecuteAlways is a line special, and it didn't exist until now.

3. The random number generator was flawed, but has been updated. Being separate from the demo-critical one, no demos were harmed.