LinuxQuestions.org
Review your favorite Linux distribution.
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
  Search this Thread
Old 02-22-2008, 03:22 AM   #1
Ashok_mittal
Member
 
Registered: Dec 2007
Posts: 73

Rep: Reputation: 15
Cool pseudo no generator srand generating similar nos every time


I have simply used srand and rand functions to generate random numbers but now i am finding every time even again compiling it is generating the similar set of numbers so what is the concept behind this ?
 
Old 02-22-2008, 04:56 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Rand() and srand() do not produce truly random numbers, as you have learned. The produce pseudo-random numbers. Rand() takes the value of srand() as the seed in producing a set of pseuro-random numbers. So long as the seed remains the same, so does the set of numbers returned by rand().

In order to produce different sets of numbers it is necessary to change the seed value of srand(). One common technique is to seed srand() with the current time (hour:minute:second). Each time srand() is called, when seeded with time, it will produce a different set of pseueo-random 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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[C++] Different output from same input ( without srand() ) sylvaticus Programming 2 02-09-2008 01:30 PM
Regarding Pseudo tty, Pseudo terminals ? mqureshi Programming 0 07-30-2005 11:51 AM
srand(), rand(), RAND_MAX, or XXX weirdness nazdrowie Programming 2 03-07-2005 01:45 PM
srand in c suchi_s Programming 14 07-27-2004 02:14 PM
Similar usb-uhci hanging at boot time problem GrayGh0st Linux - Hardware 16 06-24-2003 05:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:57 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration