Dies ist eine statische Kopie unseres alten Forums. Es sind keine Interaktionen möglich.
This is a static copy of our old forum. Interactions are not possible.

Dot

Senior Schreiberling

  • "Dot" started this thread

Posts: 618

Date of registration: Feb 3rd 2003

Location: Ex-Europameisterland

Occupation: 4TheScience

1

Saturday, November 19th 2005, 7:37pm

Script für Zufallzahlen?

Hi,kennt vielleicht jemand ein Linux-Script um Zufallszahlen zu berechnen?
Man sollte z.B. eingeben können dass aus 20 Zahlen, 3 zufällig ausgewählt werden.
Wäre sehr dankbar für eine Antwort.
C:\reality.sys has errors - Reboot the universe? (Y/N)

Real programmers don't comment their code.
It was hard to write, it should be hard to understand

denial

Erfahrener Schreiberling

  • "denial" is male

Posts: 394

Date of registration: Feb 18th 2003

Location: Göttingen

Occupation: Linux Coder (ex Mathe SR Inf Student)

2

Saturday, November 19th 2005, 8:13pm

Source code

1
2
3
4
5
6
7
8
#!/bin/bash
n=$1
shift
hexdump -vn $((n*2)) -e '1/2 "%u\n"' </dev/random | while read a
do
  x='echo ${'$((1+a%$#))'}'
  eval $x
done

?

This post has been edited 2 times, last edit by "denial" (Nov 19th 2005, 8:26pm)


Dot

Senior Schreiberling

  • "Dot" started this thread

Posts: 618

Date of registration: Feb 3rd 2003

Location: Ex-Europameisterland

Occupation: 4TheScience

3

Sunday, November 20th 2005, 10:43pm

Dankeschön!
Genau sowas hab ich gesucht,super!
Würde es dir was ausmachen,wenn du das Script nochmal erklären könntest?Begreif da nämlich nicht alles :(
Aber funktionieren tut es trotzdem :D
C:\reality.sys has errors - Reboot the universe? (Y/N)

Real programmers don't comment their code.
It was hard to write, it should be hard to understand

This post has been edited 3 times, last edit by "Dot" (Nov 20th 2005, 10:49pm)


denial

Erfahrener Schreiberling

  • "denial" is male

Posts: 394

Date of registration: Feb 18th 2003

Location: Göttingen

Occupation: Linux Coder (ex Mathe SR Inf Student)

4

Monday, November 21st 2005, 2:32am

hexdump liest die passende Anzahl 16bit Werte aus /dev/random und gibt diese dezimal aus.
Der Ausdruck aus echo und eval benutzt diese Zahlen als Index in die Parameter $2, $3, $4...

Hmm... Man könnte das shift sparen indem man das 1+ durch 2+ ersetzt...