LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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

Reply
 
LinkBack Search this Thread
Old 05-23-2008, 12:24 AM   #1
rahul_kulkarni
Member
 
Registered: Dec 2004
Posts: 32

Rep: Reputation: 15
random number generation


Hi All,

I want to know how to generate the random numbers between range 1 to n on linux platform. Is there a way to genrate the uniform random numbers over a given range? For instance, if I give n=3 and generate 100 random numbers, each number should get generated 33 times i.e. we should get number 1 33times, number 2 33 times and number 3 33 times.

Any help in this regard would be highly appreciated.

Thanks and Regards,
// Rahul
 
Old 05-23-2008, 01:11 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Which language? Also, keep in mind that if you use really random numbers, they won't appear exactly that number of times, instead the counts will approximate those ratios the longer/more nums you generate.
 
Old 05-23-2008, 01:23 AM   #3
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 61
Quote:
Originally Posted by rahul_kulkarni View Post
Hi All,

I want to know how to generate the random numbers between range 1 to n on linux platform. Is there a way to genrate the uniform random numbers over a given range? For instance, if I give n=3 and generate 100 random numbers, each number should get generated 33 times i.e. we should get number 1 33times, number 2 33 times and number 3 33 times.

Any help in this regard would be highly appreciated.

Thanks and Regards,
// Rahul
for integer numbers and small ranges of numbers:
Put all numbers you need into array with size equal to size of number range. I.e. Then mix array like a deck of cards (you'll need another random number generator for mixing, but it doesn't have to be uniform or whatever). After that each timeyou'll need random number, read element from array. Elements should be read in sequental order. When you reach last element of array, mix array again. This generator will be uniform enough, but it won't be suitable for large ranges of numbers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] uuencode for random password generation with /dev/urandom JZL240I-U Suse/Novell 27 09-06-2007 01:00 AM
Random number generation jacques83 Programming 5 02-04-2006 12:38 PM
java- static messing with random number generation titanium_geek Programming 8 10-15-2005 01:39 PM
random number generation sailu_mvn Programming 4 03-10-2005 02:10 PM
Generation of random primes SaTaN Programming 12 10-30-2003 04:30 PM


All times are GMT -5. The time now is 08:43 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration