Zufallszahlen im Terminal erzeugen

Aus Linux
Zur Navigation springen Zur Suche springen

Zufallszahl: echo $(($RANDOM % 45 + 1))

z.B.: 6 Zufallszahlen:

das 45+1 ist notwendig damit die Zahl 1 inkludiert wird

for i in {1..6}; do echo $(($RANDOM % 45 + 1)); done

Lottozahlen 6 aus 45

  1. !/bin/bash

lottozahlen=($(seq 1 45))

let "zusatzzahl=$RANDOM%10 +1"

while [[ ${#lottozahlen[*]} -gt 6 ]]

do

unset lottozahlen[$(($RANDOM%${#lottozahlen[*]}))]

lottozahlen=($(echo ${lottozahlen[*]}))

done

echo "Lottozahlen: ${lottozahlen[*]} - Zusatzzahl: $zusatzzahl"