rand31

Description

This function returns a psuedo random number. It uses a 31 bit shift register with xor feedback. The sequence of generated numbers does not repeat within 2,147,483,647 shifts.

This function will only return a maximum of 16 bits. Numbers greater than this can be built using multiple rand16 calls.

e.g.
	// generating a 19 bit random number
	ulong	acc

	acc = rand31(3) << 16
	acc = acc | rand31(16)

This function takes much longer to repeat than rand16 however it also has higher overheads.

Definition

uint rand31(uint cnt)

Library

LIB/rand_lib.bas

Usage

On entry:
cnt is the number of bits that should be returned. The maximum number is 16.
On exit:
Return a random number in the range 0 to (2^cnt)-1 (2 to the power cnt minus 1). If cnt is 4 the returned number will be in the range 0 to 15