OCLOperators random
No edit summary
No edit summary
Line 1: Line 1:
<code>Int32.Random(Int32 x)</code> returns a random integer [0..x-1].
Int32.Random(Int32 x) returns a random integer [0..x-1].


For example Int32.Random(100) will return 0, 1, ... ,99. Will never return 100.
For example Int32.Random(100) will return 0, 1, ... ,99. Will never return 100.
Example below shows one way to generate a random string with a random length (between 7-11 characters).
<code>
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( '')
  )
)
</code>

Revision as of 16:15, 25 January 2022

This page was created by Peter on 2019-12-19. Last edited by Edgar on 2025-01-20.

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

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

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( )
 )

)

MDriven Chat

How would you like to chat today?

Setting up your conversation…

This may take a few moments