C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-17-2008, 04:54 PM   #16
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Quote:
Originally Posted by Newton View Post
Hi,
The cause of my problems is that I am an idiot.
At least you realize it! I have said to myself more than once, with a rather irritated voice "You IDIOT! - What were you thinking?" [I even hit the keys hard when I wrote that to make it more emphasized, can you tell?]. As programming requires a certain level of detail mindedness, it happens that we make mistakes.
Quote:
Instead of calling srand once in the main program of my project I was calling it repeatedly in the function called from the main program. I have corrected this stupid error and removed the sleep() line and all is well.
I did think that the cause of problem was something along those lines. And if you search the forum for "srand call only once" or some such, I'm pretty sure you'll find at least two posts THIS MONTH, and many more if you read through more. When novice programmers hear about srand, they think "Ah, it makes the random numbers more random, so calling it more must make it even better" (or something like that), and then wondering why when you call srand a dozen times in a second with a time that only chances once a second, it gives the same random number a dozen times in a row...

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 09-18-2008, 04:54 PM   #17
Registered User
 
Join Date: Sep 2008
Posts: 7
Actually I had read a few quite a few "srand call only once" posts and of course everyone's helpful hints. The devil is in the details as they say. It wasn't my intention to continually call srand but that's what I was doing! All I can say is that I won't be making that mistake again.
Thanks to everyone for their help - it did lead me to realize the errors of my ways,
N.
Newton is offline   Reply With Quote
Old 09-19-2008, 02:08 PM   #18
Banned
 
master5001's Avatar
 
Join Date: Aug 2001
Location: Visalia, CA, USA
Posts: 3,699
Well you didn't murder a kitten or anything. Its just going to slow down your code while performing a redundant task. People like me get paid good money to correct code where people have done similar mistakes. Knowledge is power and even had we not told you this fact I think through mere observation you would have eventually realized what was really going on here.
master5001 is offline   Reply With Quote
Reply

Tags
generation, number, random, rapid

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Random number issue swgh C++ Programming 15 11-14-2008 10:12 AM
adding a number to a number bigmac(rexdale) C Programming 11 10-24-2007 12:56 PM
Problem with random number generation HAssan C Programming 1 03-27-2007 05:49 PM
Random number generation scrub05 C++ Programming 5 01-07-2005 08:20 AM
Prime number program problem Guti14 C Programming 11 08-06-2004 04:25 AM


All times are GMT -6. The time now is 07:51 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22