LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-09-2009, 12:30 AM   #1
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,342

Rep: Reputation: Disabled
I need a random number generator


I'm looking for a random number generating program, but to my surprise, I didn't find one in Synaptic. My graphing calculator had that function, but I gave it away some time ago.
 
Old 01-09-2009, 12:41 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,841

Rep: Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008
Language ? - everybody has one, even bash "echo $RANDOM"
 
Old 01-09-2009, 01:08 AM   #3
AuroraCA
Member
 
Registered: Jul 2008
Location: Northern CA USA
Distribution: Ubuntu, Slackware, Gentoo, Fedora, Red Hat, Puppy Linux
Posts: 370

Rep: Reputation: 35
LInux has a built in random number generator. It may need to be initialized on your system.

See: http://linux.die.net/man/4/random
 
Old 01-09-2009, 11:48 AM   #4
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,342

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
Language ? - everybody has one, even bash "echo $RANDOM"
That did what I need Syg00. Thanks. I guess my random number generator must be initialized.
 
Old 01-09-2009, 04:31 PM   #5
ichrispa
Member
 
Registered: Mar 2005
Location: Dresden, Germany
Distribution: OpenSuse 11.2/3, Debian 5.0 , Debian 1.3.1, OpenBSD
Posts: 277

Rep: Reputation: 32
There is a bunch of things you can use, especially on linux.

The kernels random number generator can be accessed through the device /dev/random. The pseudo-randoms are initiallized by the kernel at boottime, so they should be fairly irregular.

A couple of examples:

in bash, try
Code:
head -c 1 /dev/random | hexdump -d | gawk '{print $2}'
to display a single decade character. just typing
Code:
cat /dev/random
would display the ascii character corresponding to the given number.

You can also directly you awk to diplay randoms. Just go for
Code:
gawk '{print rand()*100}'
.

If you are into c or c++, i would suggest you read up on the manpage for rand (just type "man rand" without the quotes). For example:

Code:
#include <stdlib.h>
#include <stdio.h>

int main() {
 int i;

 //initialize the rng
 srand(time());
 i=rand()*100;

 printf("This is a random numer: %i\n", i);
 
 return 0;
}
The solution always depends on what you are trying to implement... there are more then enough ways.

Last edited by ichrispa; 01-09-2009 at 04:32 PM.
 
Old 05-22-2009, 02:04 PM   #6
newbiesforever
Senior Member
 
Registered: Apr 2006
Location: Iowa
Distribution: Debian distro family
Posts: 2,342

Original Poster
Rep: Reputation: Disabled
For anyone who reads this, I later found a website called random.org that has a simple random number generator.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
random number generator vkmgeek Programming 3 09-02-2008 09:41 AM
Sea Monkey Random Number Generator jschiwal General 2 02-23-2007 10:27 PM
Random number generator inside kernel space zirtik Programming 2 12-26-2005 04:02 PM
does GNU's g77 come with a random number generator? terrence Programming 1 08-30-2005 09:29 PM
Random number generator for linux Steve_Taylor Programming 12 09-30-2001 04:21 PM

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

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