looking for a program to display random words from list
Linux - SoftwareThis 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
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.
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.
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.
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)
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.
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...
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.