## ? y (Roll)

Generates a random number in a range determined by integer y.

•  y range of random number 0 'floating' in interval [0,1] 1 0 (always) >1 'integer' from list i.y

```   ? 0     NB. result will be 0 to 1
0.242499
? 0
0.80461
? 100   NB. result will be 0 to 99
30
? 100
86
? 10 # 100
91 93 17 97 58 51 16 75 42 40```

Note: the behavior of (?) can be altered by executing the Foreigns: 9!:19!:439!:45128!:4`. For details, see Entry in the J Dictionary for ?.

### Common uses

1. Make a random boolean matrix

```   ? 5 5 \$ 2
1 0 1 0 0
0 1 1 0 1
0 1 0 0 1
1 0 1 1 1
0 1 1 1 0```

2. Toss a biassed coin 10 times (1=Heads / 10% chance, 0=Tails / 90% chance)

```   0.1 > ?20#0
1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0```

3. Pick a letter at random

```(?26) { 'abcdefghijklmnopqrstuvwxyz'
f```

## x ? y (Deal)

Selects x items at random (without repetition) from the list i.y

```   3?10
4 8 9
3?10
2 4 7```

It follows that y?y permutes the items of (i.e. is a permutation of) i.y

```   10?10
7 2 6 0 5 1 3 8 4 9```

### Common uses

1. A random permutation (scrambling) of the integers 0 to 9

```   10?10
7 2 6 0 5 1 3 8 4 9
?~10   NB. -can also be written this way.
3 8 9 2 0 6 1 7 5 4```

2. Deal 3 cards from a pack of 52 cards

```   ] s=: u: 16b2660 + i.4  NB. suites
♠♡♢♣
d=: 'A23456789TJQK'     NB. denominations
pack=: , d <@,"0/ s
> (3?52) { pack         NB. deal 3 cards from 52
5♢
9♢
7♣```