RNG: Difference between revisions

From Ukikipedia
Jump to navigation Jump to search
(Created page with "{{stub}} '''RNG''' or '''Random Number Generation''' is the game's method of generating a random short. ''Todo: migrate info from Pannen's video on the subject''")
 
(still WIP, someone else please help)
Line 1: Line 1:
{{stub}}
{{stub}}
'''RNG''' or '''Random Number Generation''' is the game's method of generating a random short.
'''RNG''' or '''Random Number Generation''' is the game's method of generating a random short. By doing this, the game can make things like dust movement seem random.
 
==Technical description==
''Todo: migrate info from Pannen's video on the subject''
The RNG variable is a short, which is a number from 0 to 65535 inclusive. When an [[object]], [[snow]], or something else wants to call RNG, it takes the current RNG value and runs it through the '''RNG function''', below. It uses the result in its own calculations and also stores the result to the RNG variable. Thus, the RNG variable is equal to the last used RNG value.
===The RNG function===
<nowiki>
unsigned short rng_function (unsigned short input) {
    if (input == 0x560A) input = 0;
    unsigned short S0 = (unsigned char)input << 8;
    S0 = S0 ^ input;
    input = ((S0 & 0xFF) << 8) | ((S0 & 0xFF00) >> 8);
    S0 = ((unsigned char)S0 << 1) ^ input;
    short S1 = (S0 >> 1) ^ 0xFF80;
    if ((S0 & 1) == 0) {
        if (S1 == 0xAA55) input = 0;
        else input = S1 ^ 0x1FF4;
    }
    else input = S1 ^ 0x8180;
    return (unsigned short)input;
}
</nowiki>
===Description===
The function
==Objects that call RNG==
* [[Dust]] calls RNG to determine its resultant [[angle]] and [[horizontal speed]]. Note that the dust itself calls RNG, not the [[dust spawner]].
*

Revision as of 12:21, 10 October 2018

RNG or Random Number Generation is the game's method of generating a random short. By doing this, the game can make things like dust movement seem random.

Technical description

The RNG variable is a short, which is a number from 0 to 65535 inclusive. When an object, snow, or something else wants to call RNG, it takes the current RNG value and runs it through the RNG function, below. It uses the result in its own calculations and also stores the result to the RNG variable. Thus, the RNG variable is equal to the last used RNG value.

The RNG function

unsigned short rng_function (unsigned short input) {
    if (input == 0x560A) input = 0;
    unsigned short S0 = (unsigned char)input << 8;
    S0 = S0 ^ input;
    input = ((S0 & 0xFF) << 8) | ((S0 & 0xFF00) >> 8);
    S0 = ((unsigned char)S0 << 1) ^ input;
    short S1 = (S0 >> 1) ^ 0xFF80;
    if ((S0 & 1) == 0) {
        if (S1 == 0xAA55) input = 0;
        else input = S1 ^ 0x1FF4;
    }
    else input = S1 ^ 0x8180;
    return (unsigned short)input;
}

Description

The function

Objects that call RNG