LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2007, 08:05 AM   #16
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234

I'd forgotten that one, thanks for reminding me.

For those interested, you can find it in the bash man page w/ a case sensitive search for 'RANDOM'.

The bash code to map $RANDOM onto a range of characters is easy; in fact, the integer arithmetic assists by truncating the division. The "fun" part would come if you wanted to pick from a discontinuous set, say, letters & numbers, but no special characters.

Further fun is available in designing options for the function or program, allow or disallow upper case, for instance.


I got interested in the randomness of $RANDOM, so I wrote a little program to spit out n random lower case letters, count the number of instances of each letter, & sort the results. I tested on runs of 260, 2600, 26000, & 260000. (A run of 260000 took a minute or so on a 1 GHz P3.)

As expected, there was variation in the high & low counts & the difference converged w/ increasing n. I don't remember enough statistics to properly analyze the results, but my eyeball says there is a tendency for the median to be greater than the mean.
 
  


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
using /dev/random to output random numbers on a text file guguma Programming 4 04-02-2007 01:42 PM
KDE Random wallpaper or script to create symbolic links to random files cvelasquez Linux - Software 2 02-26-2007 06:48 PM
Broken Fedora Version? (National letters get messed up, random times) blackman890 Fedora 1 06-27-2005 07:51 AM
Creating random numbers from shell with /dev/random khermans Linux - General 1 07-13-2004 12:12 PM
non english letters bynaar Slackware 8 01-21-2003 12:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:04 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