LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


View Poll Results: What is your favorite Star Trek series?
TOS 9 29.03%
TNG 11 35.48%
DS9 5 16.13%
Voyager 2 6.45%
Enterprise 4 12.90%
Other 0 0%
Voters: 31. You may not vote on this poll

Reply
  Search this Thread
Old 07-30-2017, 04:55 AM   #1
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,717

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Question Need Code to Randomly select Star Trek Series and Episode Number.


Hi.

Can someone make a command/script that can randomly generate one of these Star Trek series acronyms (tos, tng, ds9, voy, ent) and an episode from a corresponding number range?

Example output: voy25
That being the 25th episode overall in the Voyager series.

So if tos is selected then output a number from 1-79 (there were 79 episodes in The Original Series)

For tng 1-178. (The Next Generation had the most episodes at 178)

For ds9 1-176.

For voy 1-172.

For ent 1-98.

Thanks.

Last edited by linustalman; 07-30-2017 at 04:56 AM.
 
Old 07-30-2017, 05:26 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,704

Rep: Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897
There are several ways to generate random permutations depending on how random you want to get. One easy way is using shuf.

series=$(shuf -n 1 -e tos tng ds9 voy ent)

With a case or if statements you can generate an episode number based upon the series.
episode=$(shuf -i 1-178 -n 1)

output=$series$episode
 
2 members found this post helpful.
Old 07-30-2017, 05:28 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
http://www.diveintopython.net/file_h...for_loops.html
 
Old 07-30-2017, 05:40 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
removed. beaten to it

Last edited by GazL; 07-30-2017 at 05:48 AM.
 
Old 07-30-2017, 05:45 AM   #5
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,717

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Quote:
Originally Posted by GazL View Post
I'm surprised someone who has been here since 2010 and has over 1600 posts never learned the basics of shell scripting. This is a completely trivial problem that took me less than 30 seconds (and that was just the time to type it). Where are you stuck?

hint: for loop using brace expansion piped into 'shuf -n1'
I'm not a coder.
 
Old 07-30-2017, 05:51 AM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by linustalman View Post
I'm not a coder.
It's an incredibly useful tool to have in your toolbox, even if you only spend a couple of hours to learn the very basics.
 
Old 07-30-2017, 07:26 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,704

Rep: Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897
Just because I am a Star Trek fan...

Code:
#!/bin/bash

series=("tos" "tng" "ds9" "voy" "ent")
episodes=("1-79" "1-178" "1-176" "1-172" "1-98")

num=$(shuf -i 0-4 -n 1) 
num1=$(shuf -i ${episodes[$num]} -n 1)
output=${series[$num]}$num1

echo $output
 
3 members found this post helpful.
Old 07-30-2017, 01:39 PM   #8
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,717

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Quote:
Originally Posted by michaelk View Post
Just because I am a Star Trek fan...

Code:
#!/bin/bash

series=("tos" "tng" "ds9" "voy" "ent")
episodes=("1-79" "1-178" "1-176" "1-172" "1-98")

num=$(shuf -i 0-4 -n 1) 
num1=$(shuf -i ${episodes[$num]} -n 1)
output=${series[$num]}$num1

echo $output
Hi Michael. That's perfect! Thank you.
 
Old 07-30-2017, 02:12 PM   #9
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,717

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Smile

Feel free to vote on the poll I just added. Cheers guys.
 
Old 07-31-2017, 12:38 AM   #10
khouji
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Rep: Reputation: 10
Talking

Quote:
Originally Posted by michaelk View Post
Just because I am a Star Trek fan...

Code:
#!/bin/bash

series=("tos" "tng" "ds9" "voy" "ent")
episodes=("1-79" "1-178" "1-176" "1-172" "1-98")

num=$(shuf -i 0-4 -n 1) 
num1=$(shuf -i ${episodes[$num]} -n 1)
output=${series[$num]}$num1

echo $output
Fellow Jedi can you help me also with some codes?
 
Old 07-31-2017, 04:47 AM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,704

Rep: Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897
khouji,
If this is a serious question please create a new thread.
 
Old 07-31-2017, 01:31 PM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by Habitual View Post
I raise you:

https://docs.python.org/3/library/itertools.html (permutations and combinations)
https://docs.python.org/3/library/random.html (note "shuffle" method)

Last edited by dugan; 07-31-2017 at 01:34 PM.
 
1 members found this post helpful.
Old 08-31-2017, 08:58 PM   #13
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Here we have a poll about Star Trek and no one said one thing about Star Trek in 12 posts. Amazing.

I absolutely LOVED The Next Generation when it played originally, but every time I've watched a rerun I've been disgusted by the political correctness. Maybe I was just naive the first time around.
 
Old 09-01-2017, 02:28 PM   #14
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,985

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
The TOS is the only one to watch. It always had two parts to the shows. One was tech and other was some sort of literary conflict. They didn't go overboard on PC. It was the only tech show at the time.
 
Old 09-04-2017, 04:05 PM   #15
Zyblin
Member
 
Registered: Oct 2013
Distribution: Linux Mint 18.3 (64)
Posts: 185

Rep: Reputation: 20
TOS of course. TNG very, very close second. But I also think they did a pretty good job on DS9, Voyager and Enterprise. I like the whole of it. When you add all of these together and see the larger picture of the Federation, the universe its in, etc. its great.

Individually though TOS is the one. It all started there.
 
  


Reply

Tags
episodes, random, series, star trek



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
star trek OS bloodsugar General 13 08-30-2009 07:16 PM
New Star Trek Original series movie! Kahless General 2 10-19-2007 10:49 AM
Star Trek raffytaffy General 49 09-24-2006 06:55 PM
Star trek LinuxLala General 71 12-30-2003 02:23 AM
Fav. Star Trek episode Geeky_Kid General 34 12-30-2003 02:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration