# Difference between revisions of "CoCoA:Rand"

From ApCoCoAWiki

(pushing XML rev. 1.46, again) |
m (typo 2^33 corrected) |
||

Line 6: | Line 6: | ||

In the first form, the function returns a random integer. In the | In the first form, the function returns a random integer. In the | ||

second, it returns a random integer between X and Y, inclusive. (Note: | second, it returns a random integer between X and Y, inclusive. (Note: | ||

− | |X-Y| should be less than <formula>2^33</formula> to assure a more random distribution.) | + | |X-Y| should be less than <formula>2^{33}</formula> to assure a more random distribution.) |

<par/> | <par/> | ||

NB: every time you restart CoCoA the sequence of random numbers will | NB: every time you restart CoCoA the sequence of random numbers will |

## Latest revision as of 13:31, 26 April 2008

## Rand

random integer

### Description

In the first form, the function returns a random integer. In the

second, it returns a random integer between X and Y, inclusive. (Note:

|X-Y| should be less than <formula>2^{33}</formula> to assure a more random distribution.)

NB: every time you restart CoCoA the sequence of random numbers will

be the same (as in other programming languages). If you want total

randomness read <ttref>Seed</ttref>.

#### Example

Rand(); 6304433354 ------------------------------- Rand(1,100); 8 ------------------------------- Rand(100,1); 14 ------------------------------- Rand(-10^4,0); -2747 -------------------------------

### Syntax

Rand():INT Rand(X:INT,Y:INT):INT

<type>integer</type> <type>miscellaneous</type>