LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 02-09-2008, 01:44 AM   #1
sylvaticus
Member
 
Registered: Apr 2006
Posts: 49

Rep: Reputation: 15
Question [C++] Different output from same input ( without srand() )


Hello.. I have a problem with a C++ application.
Using the same input, on the same machine, without recompiling, I got most of the times very slightly similar results (but not the same) and sometimes quite different ones.

I use extensively the random_shuffle() STL algorithm and rand() calls but I never initialize the seed with srand().

My application use also an external library, GLPK, to perform optimisations..

Can anyone give me hits on this strange behaviour ???

cheers,
Antonello
 
Old 02-09-2008, 08:38 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
So you want the same results? If so seed srand with the same constant number.
 
Old 02-09-2008, 12:30 PM   #3
sylvaticus
Member
 
Registered: Apr 2006
Posts: 49

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by dmail View Post
So you want the same results? If so seed srand with the same constant number.
Done (srand(10) just after main() ) but still slighly different results.
20% of times -> I got EXACTLY some results (I compare two scenarios with same input data)
80% of times -> I got slighly different results
 
  


Reply

Tags
c++, random



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
Sound input/output using C ashlesha Programming 5 04-02-2007 03:30 PM
dd: input/output error? logosys Linux - Newbie 3 09-19-2005 02:13 AM
Input/Output error sufiah Linux - Hardware 4 04-17-2005 07:03 PM
Input/Output error new@linux Linux - Newbie 1 01-21-2005 07:59 AM
srand in c suchi_s Programming 14 07-27-2004 01:14 PM

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

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