LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-22-2011, 02:59 PM   #1
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,375

Rep: Reputation: Disabled
looking for a program to display random words from list


Is there a Linux program I can use to display random words from a list? By entering words in a spreadsheet and then sorting the list in alphabetical order, I made a list of new vocabulary words for myself to memorize, and wondered whether I could make random words from the list display on the screen daily. I know I could write a program to do that if I knew programming, but I don't.
 
Old 04-22-2011, 03:36 PM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Hi,

I'd go with perl, here. This is the listing, tested and works here:

Quote:
#!/usr/bin/perl

# make the array
@words = ("");
$counter = 0;
# read the file
open FILE, "<words.dta" or die $!;
while ($line = readline(FILE))
{
chomp $line;
push(@words, $line);
$counter++;
}
close(FILE);

# choose one
$random_number = int(rand($counter));
print @words[$random_number] . "\n";
Steps to follow:
- open gedit (or any other editor for plain text)
- copy & paste the listing shown
- save somewhere as "words.pl"
- compile a plain text file of your words (learning a new language? cool) enter one word and hit enter after each word
- place this file in the same folder and make sure it is called words.dta
- enter the console, navigate to the folder where "words.pl" is located
- enter
Quote:
chmod +x words.pl
- test, just enter this
Quote:
./words.pl
one of the words in the list should apear on the console

Hope this helps!

I'll watch this thread to see how you get along!

Thor
By the way - Perl is not my native language, so if anyone can improve on this, please do so! Tnx

Last edited by ButterflyMelissa; 04-22-2011 at 03:39 PM.
 
Old 04-22-2011, 04:20 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
How about something fun. Create a directory of pictures to use for your wallpaper, and use ImageMagick to print each of the words on a different picture. (or use the same source picture and create a picture for each word if you like a particular wallpaper background)

Code:
words=(cat wordlist)
pictures=(ls wallpapers/*.jpg)

for ((n=1; n<${#words[*]}; n++)); do 
    convert -font Bookman-DemiItalic -pointsize 70 -draw "text 25,60 $work" \
            -channel RGBA -blur 0x6 -fill darkred -stroke magenta           \
            -draw "text 20,55 ${words[$n]}" \
            "${pictures[$n]}" "$n-${pictures[$n]}"
done
Let kde or gnome display the backgrounds in random order. The let you select a directory of pictures to use as the wallpaper. KDE also has a Widget to display pictures which could use a directory as well.

The convert command is taken from the documentation for ImageMagick.

Last edited by jschiwal; 04-22-2011 at 04:24 PM.
 
Old 04-22-2011, 04:25 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Why not just use one of the many available vocabulary trainers?
 
Old 04-22-2011, 04:34 PM   #5
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Quote:
Why not just use one of the many available vocabulary trainers?
Assuming OP is leaning a language, it could as well be a set of terms for his job...

But, the entry on the wallpaper, now that one I did'nt see comming

Cool going there, jschiwal!

Thor
 
Old 04-22-2011, 10:09 PM   #6
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,375

Original Poster
Rep: Reputation: Disabled
Nope, this is not for my job. It's for nothing but my self-improvement. I feel that my vocabulary isn't what it used to be. Ehh, about these solutions, I guess I'll have to decide which is the simplest...
 
Old 04-22-2011, 10:14 PM   #7
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Use the perm -n 1 <file_name> command.
 
Old 04-22-2011, 10:28 PM   #8
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,375

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by PTrenholme View Post
Use the perm -n 1 <file_name> command.
Hmm...I'd sure like to apply that solution, as it's the simplest by far; but I don't seem to have a program "perm"--my terminal said command not found. Looking for it...

If I didn't think there must be some other explanation, I'd wonder if you were playing a joke on me. I looked up "perm," and it seems to be a parameter meaning "permissions," often used in the "find" command...

Last edited by newbiesforever; 04-22-2011 at 11:16 PM.
 
Old 04-23-2011, 12:21 AM   #9
Ahiri
LQ Newbie
 
Registered: Apr 2011
Posts: 4

Rep: Reputation: 0
Here's a python version of Thor's perl solution:
Code:
import random, os
f = open('word.list','r')
s = f.read()
f.close()
l = s.split(',')
m = len(l)-1
n = random.randint(0,m)
os.system('xmessage '+l[n])
Though this could be simplified to just:
Code:
import random, os
f = open('word.list','r')
os.system('xmessage '+f.read().split(',')[random.randint(0,len(l)-1)])
f.close()
Or even:
Code:
import random, os
os.system('xmessage '+open('word.list','r').read().split(',')[random.randint(0,len(l)-1)])
Though that's bad practice because you don't close the file but python should do it for you. Just put all the words in a comma-deliminated file named word.list (excel or open office or whatever spreadsheet you're using should be able to export to this). Then all you have to do is use cron to run "python vocab.py" however often you need and you're done.

Last edited by Ahiri; 04-23-2011 at 12:37 AM.
 
Old 04-23-2011, 12:09 PM   #10
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
@ Ahiri - WOW! THAT IS PYTHON??? I'm off for a tutorial!

Tnx!
 
Old 04-23-2011, 01:21 PM   #11
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by newbiesforever View Post
Hmm...I'd sure like to apply that solution, as it's the simplest by far; but I don't seem to have a program "perm"--my terminal said command not found. Looking for it...

If I didn't think there must be some other explanation, I'd wonder if you were playing a joke on me. I looked up "perm," and it seems to be a parameter meaning "permissions," often used in the "find" command...
Oops! My bad. I was on an old XP system when I posted that, so I was working from my faulty memory. The correct command is shuf, not "comb." (I was thinking "combinatorial," since I was a statistician for many years before retiring. The program author obviously thought of "shuffling" cards when the program was created.)

If your system installs the manual pages (which Ubuntu, by default, does not), man shuf at the command line should give you a good description of the shuf command and its options. (And, for example, man -k random will list all commands - and library functions - related to randomness.)

Last edited by PTrenholme; 04-23-2011 at 01:23 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python: replacing all words found on a list General Programming 3 03-15-2010 08:57 AM
Getting Range of Words from Arg List tonyfreeman Programming 3 10-05-2006 03:35 PM
Bash - How to make For read lines instead of words in a list ? landuchi Programming 10 02-15-2006 01:36 PM
Sorting a list of words in LISP! Hady Programming 1 05-01-2004 03:29 PM
This might sound strange, but I need a big list of dirty words. Travis86 Programming 12 07-17-2003 11:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:09 AM.

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