sixwheeledbeast | can random be used in a loop on the shell without having the same number come up | 14:15 |
---|---|---|
KotCzarny | ? | 14:17 |
KotCzarny | try: echo $RANDOM | 14:17 |
KotCzarny | works in bash | 14:17 |
sixwheeledbeast | to avoid xy I need to pull a random list of say 50 integers from a pool of 01-99 . I beleive RANDOM will repeat them if in a loop | 14:17 |
KotCzarny | it returns 0-32767 i think | 14:17 |
KotCzarny | up to you to scale it to range you need | 14:18 |
sixwheeledbeast | i want no duplicates | 14:18 |
KotCzarny | thats not random then | 14:18 |
KotCzarny | what you need is to create an array with 99 elements, then shuffle it | 14:18 |
sixwheeledbeast | well I suppose so but that's what i am looking for | 14:18 |
sixwheeledbeast | i see is array the best way you think? | 14:19 |
KotCzarny | otherwise you have to keep different array with 'used' numbers anyway | 14:19 |
KotCzarny | and having to scan through it on every new return | 14:19 |
sixwheeledbeast | I suppose so. I didn't think of it like that. i was hoping for a shell function already there :) | 14:20 |
KotCzarny | i havent seen such functionality in bash | 14:21 |
KotCzarny | anyway, your problem is 'shuffle deck of cards then deal them' | 14:21 |
KotCzarny | taught in schools often | 14:21 |
KotCzarny | so there should be lots of examples for different languages | 14:22 |
sixwheeledbeast | np array it is then. school? | 14:22 |
KotCzarny | ya, it101 | 14:22 |
sixwheeledbeast | school is long behind me we where lucky to have working ones in my era | 14:23 |
KotCzarny | but as i've said, google: deal shuffled deck of cards in bash | 14:23 |
Maxdamantus | or a more interesting way of looking at it: find an information densitity preserving encryption, and encrypt all possible inputs in a predictable sequence. | 14:26 |
KotCzarny | or basically: shuffle in bash | 14:27 |
Maxdamantus | basically, encrypt(0), encrypt(1), encrypt(2), .. encrypt(n) | 14:27 |
sixwheeledbeast | yep i am waiting for something to render so can't open a browser at the moment, hence I thought I'd ask the question having used random before. | 14:27 |
KotCzarny | swb: but it's better to use any scripting lang, perl/php/python | 14:27 |
KotCzarny | whichever you are best in | 14:28 |
KotCzarny | at some point you will have to switch to it when adding functionality | 14:28 |
Maxdamantus | anyway, if you want a sequence of numbers in a random order: seq 99 | sort -R | head -50 | 14:28 |
KotCzarny | wow | 14:29 |
sixwheeledbeast | only ever used bash for most things but i can have a look in python if necessary. | 14:29 |
KotCzarny | i forgot sort has shuffle | 14:29 |
Maxdamantus | (`seq 99` is a bit weird; I suspect what you really want is either `seq 0 99` or `seq 100`, which both emit 100 numbers (`seq 99` emits 99 numbers)) | 14:29 |
sixwheeledbeast | oh useful ty :) | 14:30 |
KotCzarny | seq -f '%02.0f' 1 99|sort -R | 14:30 |
KotCzarny | done | 14:30 |
KotCzarny | if you want only 50 of them, add |head -50 | 14:31 |
sixwheeledbeast | oh i see you have used the format flag to have 2sf nice | 14:33 |
KotCzarny | Mangy_Dog: pink screen on hdmi means hdmi pixel format failed | 17:20 |
KotCzarny | erm, wrong chan | 17:20 |
Generated by irclog2html.py 2.17.0 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!