Wrox Programmer Forums > Mac Chapter 6 - Pg 177 Statistical Analysis
 |
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 Read more about Beginning Mac OS X Programming or buy the book from your favorite retailer Download the code for Beginning Mac OS X Programming
 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

January 30th, 2011, 07:26 PM
 [email protected] Registered User Join Date: Jan 2011 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts
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

January 31st, 2011, 01:49 AM
 thepianoguy Friend of Wrox Join Date: Aug 2010 Posts: 298 Thanks: 1 Thanked 62 Times in 60 Posts

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.
Bob

 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 [email protected] 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