ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've got it, I had to adjust it without using shuf because I don't have that command, after reading a post I realized it wasn't too much to rework. Thanks for the help. How did you come up with that logic?
Last edited by Lucien Lachance; 08-20-2013 at 09:51 AM.
I had to adjust it without using shuf because I don't have that command
Well that is a little weird as it is a part of the coreutils package, which is pretty standard on most distros, at least that I have used (which is a few )
Quote:
How did you come up with that logic?
Can't obviously speak for PT as the author, but essentially you told us the logic with your python example.
As an alternative to shuf you could combine min86's suggestion with PT's script to get:
Code:
#!/bin/bash
declare -A moves
moves=(['r']="rock" ['p']="paper" ['s']="scissors")
tmp=(${!moves[*]})
for ((i=0;i<10;++i))
do
key=${tmp[RANDOM % ${#tmp[*]}]}
echo key=${key}
echo "move ${i} = ${moves[${key}]}"
done
I wish the man pages weren't always so terse, I have to get the hang of that still. Most of the time I know, or have an idea of how it needs to be solved and go from there. Do you usually know where to begin looking in the docs, or does it usually take you awhile to figure things out? I hope this makes sense..
The man pages are intentionally terse. They are supposed to be used to "remind" command users about things they seldom use. The info files are (usually) more complete, often with examples. (If you have the pinfo command installed, it makes using the info system much easier and intuitive.)
I see, I found this helpful link as well concerning lower case and upper case submissions: http://mintaka.sdsu.edu/GF/bibliog/l...bian/bash.html
Really puts things into perspective, I had always thought using tr, awk, or perl were the only ways of achieving this. Thank you pointing out that bash could handle this problem natively @grail.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.