# Differences

This shows you the differences between two versions of the page.

 cl:functions:random [2019/07/14 17:00] cl:functions:random [2019/10/17 13:00] (current) Line 1: Line 1: + ====== Function RANDOM ====== + + ====Syntax==== + * **random** //limit ''&​optional''​ random-state//​ → //​random-number//​ + + ====Arguments and Values==== + * //limit// - a positive //​[[CL:​Glossary:​integer]]//,​ or a positive //​[[CL:​Glossary:​float]]//​. + * //​random-state//​ - a //​[[CL:​Glossary:​random state]]//. The default is the //​[[CL:​Glossary:​current random state]]//. + * //​random-number//​ - a non-negative //​[[CL:​Glossary:​number]]//​ less than //limit// and of the same //​[[CL:​Glossary:​type]]//​ as //limit//. + + ====Description==== + Returns a pseudo-random number that is a non-negative //​[[CL:​Glossary:​number]]//​ less than //limit// and of the same //​[[CL:​Glossary:​type]]//​ as //limit//. + + The //​random-state//,​ which is modified by this function, encodes the internal state maintained by the random number generator. + + An approximately uniform choice distribution is used. If //limit// is an //​[[CL:​Glossary:​integer]]//,​ each of the possible results occurs with (approximate) probability ''​1<​nowiki>///​limit//''​. + + ====Examples==== + + <​blockquote> ​ + ([[CL:​Functions:​math-not-greater|<​=]] 0 (random 1000) 1000) <​r>//​[[CL:​Glossary:​true]]//​ + ([[CL:​Special Operators:​let]] ((state1 ([[CL:​Functions:​make-random-state]])) ​ + (state2 ([[CL:​Functions:​make-random-state]]))) + ([[CL:​Functions:​math-equal|=]] (random 1000 state1) (random 1000 state2))) <​r>//​[[CL:​Glossary:​true]]//​ + ​ + + ====Side Effects==== + The //​random-state//​ is modified. + + ====Affected By==== + None. + + ====Exceptional Situations==== + Should signal an error of type type-error if //limit// is not a positive //​[[CL:​Glossary:​integer]]//​ or a positive //​[[CL:​Glossary:​real]]//​. + + ====See Also==== + * **[[CL:​Functions:​make-random-state|Function MAKE-RANDOM-STATE]]** + * **[[CL:​Variables:​star-random-state-star|Variable *RANDOM-STATE*]]** + + ====Notes==== + See //Common Lisp the Language// for information about generating random numbers. +