Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mac > BOOK: Beginning Mac OS X Programming
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Mac OS X Programming
This is the forum to discuss the Wrox book Beginning Mac OS X Programming by Michael Trent, Drew McCormack; ISBN: 9780764573996
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Mac OS X Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 30th, 2011, 07:26 PM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 6 - Pg 177 Statistical Analysis

I downloaded the chapter programs from this website and ran the Statistical Analysis of Array Data program, and instead of random numbers, I get exactly what is displayed in figure 6-2. It's supposed to generate random numbers, but I get the same results on every run. What's wrong with the line...

float randNum = (float) rand() / RAND_MAX; // From 0.0 to 1.0
  #2 (permalink)  
Old January 31st, 2011, 01:49 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

rand() is not actually random, it is pseudo-random. You need to seed it first to create the "illusion" of randomness. If the seed doesn't change, the random numbers generated will be the same. A common technique is to seed with time()
srand(time(NULL));
Then use the program as written.
The value returned is what rand() will generate the pseudo-random numbers from. Unless the program is run at precisely the same time the numbers generated will change, since the seed will be different.
Google rand() and srand() for more info.
Bob
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Chapter 9 Reporting With Analysis Services. RiazFarooqui BOOK: Professional Microsoft SQL Server 2008 Reporting Services ISBN: 978-0-470-24201-8 4 September 7th, 2009 02:42 PM
Chapter 2, pg 39 Bodman@live.ca BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 2 April 21st, 2009 01:42 AM
Chapter 3 pg 95 al2000 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 August 4th, 2008 09:18 PM
Statistical Functions leehambly Access 1 January 17th, 2007 07:27 AM



All times are GMT -4. The time now is 02:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.