A.42 library(random): Random numbers
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(random): Random numbers
          • random/1
          • random_between/3
          • random/3
          • setrand/1
          • getrand/1
          • maybe/0
          • maybe/1
          • maybe/2
          • random_perm2/4
          • random_member/2
          • random_select/3
          • random_subseq/3
          • randset/3
          • randseq/3
          • random_permutation/2
          • random_numlist/4
    • Packages
Availability::- use_module(library(random)).(can be autoloaded)
Source[det]randset(+K:int, +N:int, -S:list(int))
S is a sorted list of K unique random integers in the range 1..N. The implementation uses different techniques depending on the ratio K/N. For small K/N it generates a set of K random numbers, removes the duplicates and adds more numbers until |S| is K. For a large K/N it enumerates 1..N and decides randomly to include the number or not. For example:
?- randset(5, 5, S).
S = [1, 2, 3, 4, 5].          (always)
?- randset(5, 20, S).
S = [2, 7, 10, 19, 20].
See also
randseq/3.