jeudi 3 janvier 2019

Assigning random values to the elements of a list

I want to assign to the elements of a list a random value out of a list. For example: given the assigning list '(0 1) and whatever list '(a b c d) I want as the output a list such as '((a 0) (b 0) (c 1) (d 0)) or '((a 1) (b 0) (c 0) (d 1)) for example.

My attempts are:

  1. (map cons '(a b c d) (circular-list (random '(0) '(1))))

which gives '((a . 0) (b . 0) (c . 0) (d . 0)) or '((a . 1) (b . 1) (c . 1) (d . 1)) and nothing different and

  1. (map cons '(a b c d) (list (random '(0) '(1))))

which gives '((a . 0)) or '((a . 1)) and nothing different.

I am making use of a function

random

which takes randomly 0 or 1.

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire