Mark Six master on Linux/Mac

A Mark six ticket

Mark six is a lottery in Hong Kong. You can pick 6 numbers from 49 numbers in the lottery ticket. There are many single line command to generate 6 numbers from 1 to 49,

jot on Mac

1
jot -r -s ' ' 6 1 49 | tr ' ' '\n'

python 2

1
python -c 'import random; print [ random.randint(1,49) for _ in xrange(6)]'

awk

1
awk -v min=1 -v max=49 'BEGIN{ srand(); for (i = 0; i < 6; i++)  print int(min+rand()*(max-min+1))}'
bash
1
for i in {1..6}; do echo $(( ( RANDOM % 49 ) + 1)); done
However, you will soon find repeated numbers are generated from the above solutions. The trick to have non-repeated generated is using random sort from an array with 49 numbers, jot on Mac
1
jot 49 1 49 | gsort --random-sort | head -n 6
python 2
1
python -c 'import random; a = range(1, 49); random.shuffle(a); print a[:6:]'
Share