OCLOperators random

Int32.Random(Int32 x) returns a random integer [0..x-1].

For example, Int32.Random(100) will return 0, 1, ... ,99 - it will never return 100.

The example below shows one way to generate a random string with a random length (between 7-11 characters).

let characters = 'ABCDEFGHJKLMNPQRST23456789'.toCharArray in (
  let wordlength = Int32.Random(5)+7 in (
    Sequence{1..wordlength}->collect(a|characters->at(Int32.Random(100).Mod(tecken->size)+1))->asSeparatedList( '')
  )
)
This page was edited 97 days ago on 02/10/2024. What links here