How to resolve the algorithm Pick random element step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pick random element step by step in the CLU programming language

Table of Contents

Problem Statement

Demonstrate how to pick a random element from a list.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pick random element step by step in the CLU programming language

Source code in the clu programming language

random_element = proc [T: type] (a: array[T]) returns (T)
    return(a[array[T]$low(a) + random$next(array[T]$size(a))])
end random_element

start_up = proc ()
    po: stream := stream$primary_output()
    d: date := now()
    random$seed(d.second + 60*(d.minute + 60*d.hour))
    
    arr: array[string] := array[string]$["foo", "bar", "baz", "qux"]
    
    for i: int in int$from_to(1,5) do   
        stream$putl(po, random_element[string](arr))
    end
end start_up

  

You may also check:How to resolve the algorithm Cumulative standard deviation step by step in the Fortran programming language
You may also check:How to resolve the algorithm ABC problem step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the APL programming language
You may also check:How to resolve the algorithm Execute HQ9+ step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Permutations step by step in the Aime programming language