Hello,
I'm just starting out with Obj-C / Cocoa (from having done no previous C or C++ programming). I wrote this to generate a random number in a window and wondered if it was a tidy enough way to achieve the goal....
{See next post with code}
This objective-C thing is hard work man! Seriously.
This code does work, but wondered if it is better written another way? Also, if you click the button twice quickly - the random number isn't random (I think because the seed is from 'time'). Is there a better way to generate a better seed (perhaps using Milliseconds?)
EDIT: I changed the seed line to the following, which gives better results when updating fast...
I'm just starting out with Obj-C / Cocoa (from having done no previous C or C++ programming). I wrote this to generate a random number in a window and wondered if it was a tidy enough way to achieve the goal....
{See next post with code}
This objective-C thing is hard work man! Seriously.
This code does work, but wondered if it is better written another way? Also, if you click the button twice quickly - the random number isn't random (I think because the seed is from 'time'). Is there a better way to generate a better seed (perhaps using Milliseconds?)
EDIT: I changed the seed line to the following, which gives better results when updating fast...
Code:
srandom(time(NULL)+(random()%100)+1);