Watch out for confusion:
Obtaining a pseudo-random float using the built-in random_float/0 function
?- X is random_float(). X = 0.9494465703010132. % or ?- X is random_float. X = 0.8947004522094781.
Obtaining a pseudo-random integer using the built-in random/1 function
" random/1 called in a function context "
?- X is random(0xFFFF). X = 48881.
" random/1 called in a predicate context "
This actually just calls random_float/0:
?- random(X). X = 0.03479878770414104.
You also have other nice predicates like:
?- random_between(5,100,X). X = 46. % same as ?- random(5,100,X). X = 23. % floaty: ?- random(0.5,0.8,X). X = 0.7333403405858778.
Useful for random execution path selection (Randomized Algorithms)
?- (maybe -> write("heads"); write("tails")).
?- random_member(X,[1,2,3,4,5,6]). X = 2.
As said above, for non pseudo-random numbers (read probably from /dev/random instead of /dev/urandom; watch out as /dev/random blocks if there is not enough randomness and waits until there are enough), use library(crypto), also auto-loaded:
?- crypto_n_random_bytes(5,Bytes). Bytes = [222, 115, 198, 244, 228].
Still need more bytes?
Use the HTTP connector to get your bytes from Internet paid services such as https://api.random.org/json-rpc/2 (no affiliation)