Page MenuHomeFeedback Tracker

Unary random <SCALAR> can roll the input value.
Closed, ResolvedPublic

Description

It is possible for random 10 to output 10. See code below,

[] spawn {
    private _attempt = 0;
    while {true} do {
        if (_attempt % 50000 == 0) then {
            systemChat str (_attempt toFixed 0);
        };
        if (random 10 == 10) exitWith {
            systemChat str ["hit", _attempt toFixed 0];
        };
        _attempt = _attempt + 1;
    };
};

Depends how lucky you are :D
From wiki: Number from 0 (included) to x (excluded), yet it is possible.

Details

Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
Scripting
Steps To Reproduce

Run

[] spawn {
    private _attempt = 0;
    while {true} do {
        if (_attempt % 50000 == 0) then {
            systemChat str (_attempt toFixed 0);
        };
        if (random 10 == 10) exitWith {
            systemChat str ["hit", _attempt toFixed 0];
        };
        _attempt = _attempt + 1;
    };
};

And try to be lucky.

Event Timeline

sharp1337 created this task.Oct 9 2022, 9:52 PM
jaj22 added a subscriber: jaj22.Jan 18 2023, 12:42 AM
jaj22 added a comment.Mar 8 2024, 10:30 PM

Much faster repro by abusing isNil. Typically generates the fail case well within a minute:

[] spawn { 
    private _attempt = 0; 
    private _nohit = true;
    while {_noHit} do { 
        systemChat str _attempt;
        isNil {   
            for "_i" from 1 to 100000 do {
                if (floor random 1000 == 1000) exitWith { 
                    systemChat "hit";
                    _noHit = false;
                };
            };
        };
        _attempt = _attempt + 100000;
    }; 
};

The floor doesn't make a difference to the result (FP won't report a normalized value as equal unless the bits match) but was added on request.

SaMatra added a subscriber: SaMatra.Mar 9 2024, 2:02 AM
BIS_fnc_KK set Ref Ticket to AIII-56278.

Revision: 151549

BIS_fnc_KK removed BIS_fnc_KK as the assignee of this task.Mar 9 2024, 3:27 AM
BIS_fnc_KK changed the task status from New to Feedback.
BIS_fnc_KK added a subscriber: BIS_fnc_KK.
dedmen added a subscriber: dedmen.Mar 11 2024, 9:37 AM

We found that this change was done in October 2008. That was before Arma 2 release, its been like that since then.

The fix on dev seems to work, whatever it is. Tested with 1, 10, 1000 and 1e6. Also checked for bias in the last value, seems fine.

Wulf closed this task as Resolved.Apr 25 2024, 5:53 PM
Wulf claimed this task.
Wulf added a subscriber: Wulf.

Fixed in Dev build 151757.