• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: random value (newbie)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: random value (newbie)


  • Subject: Re: random value (newbie)
  • From: Sherm Pendley <email@hidden>
  • Date: Tue, 10 Jun 2003 18:35:25 -0400

On Monday, June 9, 2003, at 04:17 PM, Alexander Moss wrote:

- (long)calc_it;
{
random(void);
}

No offense meant, but you need to familiarize yourself with the basics of calling a C function. Quite a bit of what you'll learn will also apply to Objective-C methods, so it's time well spent.

According to its man page, the random() function is declared like this:

long random(void);

What this means is, it returns a long int, and takes no arguments. It does *not* mean that you should simply type the word "void" as the argument to pass to it.

Also, in the above method, you're not doing anything with the value returned by random() - it's just getting thrown away. You need to explicitly return it from your method.

So, the above method should read like this:

- (long) calc_it;
{
return random();
}

sherm--

"But i don't want to go among mad people," Alice remarked.
"Oh, you can't help that," said the Cat: "we're all mad here. I'm mad, You're mad."
"How do you know I'm mad?" said Alice.
"You must be," said the Cat, "or you wouldn't have come here."
"Alice in Wonderland" - Lewis Carrol
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >random value (newbie) (From: Alexander Moss <email@hidden>)

  • Prev by Date: Any Cocoa/MOSX user groups in MD,VA,DC??
  • Next by Date: Re: using a virtual C++ function
  • Previous by thread: random value (newbie)
  • Next by thread: Orange County, San Diego, or Los Angeles Cocoa groups?
  • Index(es):
    • Date
    • Thread