Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(2 edits) (+2)

As far as I understand it, which is probably not that far ;), random takes a bitmask as an argument. The bitmask is a value that gets ANDed with a random number from 0 to 255. So:

v0 := random 0xFF   # v0 is a random number from 0 to 255
v0 := random 0x01   # v0 is randomly 0 or 1
v0 := random 0x07   # v0 is a random number from 0 to 7
v0 := random 0x08   # Careful: v0 is randomly 0 or 8 ;)
(1 edit) (+2)

Exactly; the argument is an AND mask.

Sometimes it's clearer to write the argument to `random` in binary (e.g. `0b1100`) instead of hex or decimal. Then just imagine that every 1 in that mask could wind up as either 1 or 0 in the result.