samedi 12 novembre 2016

Random function in Racket

Hello I have this function that makes randomly: a, b, c or d.

(define random-abcd
  (let ([n (random 4)])
    (cond [(equal? n 0) 'A]
          [(equal? n 1) 'B]
          [(equal? n 2) 'C]
          [else 'D])))

That means I have 4 possible random outputs. But I would like to build a recusrsive function that gives an output between a number I give as parameter.

For example:

random-my 3 -> gives and output between: a b or c

random-my 5 -> gives and output between: a b c d or e

Thank you!




Aucun commentaire:

Enregistrer un commentaire