(Note: This page contains only information about the "Lucky Draw" level in Famidash v1.2.1.nes and how randomness works. If other information about Famidash in general is to be added, consider moving the below information to a subpage. Outdated information on Lucky Draw v1.2 is on this subpage.)

Lucky Draw

Known source code files implementing random functions:

_newrand

Based on the source code's _newrand function, the main pseudo-random number generator (PRNG) is a simple 32-bit, period 2^32-1 linear feedback shift register (LFSR) that is equivalent to the following Lua code:
local function _newrand(rng)
	for i=1,8 do
		if rng>=0x80000000 then
			-- & means bitwise AND, ~ means bitwise XOR
			rng = ((rng*2)&0xFFFFFFFF)~0xC5
		else
			rng = rng*2
		end
	end
	return rng
end
The above PRNG auto-runs once per frame in most cases, without using this value. In rare instances, Famidash runs this function to get a random value. (Famidash typically does not have randomness in its levels.)

rand1

As of v1.2.1, rand1 uses an RNG address different from that of _newrand, in order to fix incorrect Lucky Draw behavior. Whether an attempt is successful in Lucky Draw no longer uses rand1 anywhere in its determination.
The rand1 operates on a single byte and is a LFSR as follows:
local function rand1(rng2)
	local lbyte=rng2&0xFF
	if lbyte>=0x80 then
		-- & means bitwise AND, ~ means bitwise XOR
		lbyte=((lbyte*2)&0xFF)~0xCF
	else
		lbyte=lbyte*2
	end
	-- | means bitwise OR
	return ((rng2&0xFFFFFF00)|lbyte)
end
The above function can run multiple times per frame (as well as running _newrand during the same frame), and determines the flashing effects on some objects.

How Lucky Draw determines whether an attempt is successful

When first selecting Lucky Draw, as well as after any death, the RNG address for _newrand (0x1B, four byte little endian) will freeze on a particular value. As far as is known, this value is the only thing that determines whether the first/following attempt is a successful attempt. No player input that changes RNG has been found.
As of v1.2.1, whether an attempt is successful in Lucky Draw no longer uses rand1 anywhere in its determination.
The following procedure determines whether an attempt is successful:
(some # of frames): run _newrand x49
(next frame): run _newrand x2:
- If RNG values are equal mod 64: kill player.
- Otherwise: run _newrand x1 and continue.

At this point, the distance is 13504.
The next distance at which player survival check occurs is 16640.

Repeat the following until distance is 3286588:
{
If distance has not yet reached/exceeded
the next survival check distance:
- Run _newrand x1 then add 708 to distance.
Otherwise, if distance has reached/exceeded
the next survival check distance:
- Run _newrand x2:
-- If RNG values are equal mod 64: kill player.
-- Otherwise: Run _newrand x1, then add 4096 to get
the next check distance, then add 708 to distance.
}

Once the distance is 3286588:
'''Success: Player will beat the level.'''
If the attempt is unsuccessful, the RNG value when the player was killed will be the new RNG value for the next attempt.
Expand/Collapse collapse-content-_4bb0ccd5cbd04095b077e5e0cada7ca3

GameResources/NES/Famidash last edited by FractalFusion on 4/12/2025 10:42 PM
Page History Latest diff List referrers View Source