nn::math::TinyMt::GenerateRandomN Member Function

Syntax

#include <nn/math.h>

u32 GenerateRandomN(
     u16 max
);

Parameters

Name Description
max
in num Specifies the type of return value.

Return Values

Returns a random integer in the specified range.

Description

Generates a random number that is less than the specified number.

Generates a random number in the range of integers from 0 to less than num. The return value type is the type of num.

Note that the return rate of each value is not completely equal. For example, when 6 is specified for num, the probability that 0, 1, 3 or 4 is returned is 0x2AAAAAAB / 0x100000000 but the probability that 2 or 5 is returned is 0x2AAAAAAA / 0x100000000; the probability that 2 or 5 appears is 0x2AAAAAAA / 0x2AAAAAAB times the probability that 0, 1, 3 or 4 appears.

The bias in the probability increases with a larger num; when the maximum value, 0xFFFF, is specified for num, the probability that 0 appears is 65538 / 65537 times (1.0000153 times) the probability that a non-zero number appears.

The bias does not occur when num is a power of 2.

Revision History

2012/05/11
Initial version.

CONFIDENTIAL