{{fbdoc item="title" value="RND"}}----
Returns a random [[KeyPgDouble double]] precision number in the range ##[0, 1)##

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Rnd** ( [[KeyPgByval byval]] //seed// [[KeyPgAs as]] [[KeyPgSingle single]] = 1.0 ) [[KeyPgAs as]] [[KeyPgDouble double]]
##
{{fbdoc item="usage"}}##
	//result// = **Rnd**( //seed// )
##
{{fbdoc item="param"}}
	##//seed//##
		Optional ##[[KeyPgSingle single]]## argument. If ##//seed//## has a value of zero (##0.0##), the last random number generated is repeate.  For any other number a new random number is returned. With the QB-compatible algorithm, a negative number fully reseeds the generator.  The default for no argument is to return a new random number.

{{fbdoc item="ret"}}
	Returns the random number generated.

{{fbdoc item="desc"}}
	Returns a number of type ##[[KeyPgDouble double]]## in the range ##[0, 1)## (i.e. ##0 <= **Rnd** < 1##), based on a random seed (see ##[[KeyPgRandomize Randomize]]##).

	##**Rnd**## can use a variety of different algorithms - see ##[[KeyPgRandomize Randomize]]## for details of the default and selectable algorithms.

	##**Rnd**## will return the same sequence of numbers every time a program is run.  This sequence can be changed by reseeding the generator.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/math/rnd.bas"}}%%(freebasic)
'' Function to a random number in the range [first, last), or {first <= x < last}.
function rnd_range (first as double, last as double) as double
	function = rnd * (last - first) + first
end function

'' seed the random number generator, so the sequence is not the same each time
randomize

'' prints a random number in the range [0, 1), or {0 <= x < 1}.
print rnd

'' prints a random number in the range [0, 10), or  {0 <= x < 10}.
print rnd * 10

'' prints a random integral number in the range [1, 11), or  {1 <= x < 11}.
'' with integers, this is equivalent to [1, 10], or {1 <= n <= 10}.
print int(rnd * 10) + 1

'' prints a random integral number in the range [69, 421), or {69 <= x < 421}.
'' this is equivalent to [69, 420], or {69 <= n <= 420}.
print int(rnd_range(69, 421))
%%

{{fbdoc item="lang"}}
	The default algorithm used depends on the current dialect in use:
		- With the //[[CompilerOptlang -lang fb]]// dialect, a 32 bit Mersenne Twister function with a granularity of 32 bits is used.
		- With the //[[CompilerOptlang -lang qb]]// dialect, a function giving the same output as ##**Rnd**## in QB is used. The granularity is 24 bits.
		- With the //[[CompilerOptlang -lang deprecated]]// and //[[CompilerOptlang -lang fblite]]// dialects, the function in the C runtime available in the system is used. The function available in Win32 has a granularity of 15 bits, and 32 bits in Linux and DOS.

{{fbdoc item="diff"}}
	- None, if compiled in the //[[CompilerOptlang -lang qb]]// dialect.  Other dialects can also use the same seeding and generating algorithms by calling ##[[KeyPgRandomize Randomize]]## with the appropriate parameter.
	- For the non-QB-compatible algorithms, if the optional argument is less than 0, it has the same meaning as passing an argument of 1.

{{fbdoc item="see"}}
	- ##[[KeyPgRandomize Randomize]]##
	- ##[[KeyPgTimer Timer]]##
	- ##[[KeyPgInt Int]]##

{{fbdoc item="back" value="CatPgMath|Math"}}