site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=IKD+bTi3jMyQ0jgDSlQWohroY6QR6r6xXv6Kvc200IQ=; b=uqpvQX8H9nIgdpP1pz8jVofXVNWnQ0TocdWGijqDJFn3QBe0piNNQHND1Ty+dT+bVAJUWc3jU3FxE1pYQFXsL9q9yKDPK/h7Tin5BkUCRlj1Gu+hu0MVVYCtN3r3j8VYrcm+4Av2xi9GuaymJBmv9i/Wgoqi2Ct5WkuM92QruGk= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Gd6JMOvNF2uA5B4lGTXX3BUbqRRPQYNAOTYnZ+HZlX4rBqfBt/sUg2LsTyroPmblgA8IYgVtWPiJ1f2xVs4oWcE99yZ2sx0LAgK9mBu/ddWLAGYgijCXG8d+LxiwFkIQujBhxxOl2G5JXGmiuZOUgs+hRzQ3dAUZ6yKurGl8qiE= On Nov 14, 2007 10:57 AM, A.M. <agentm@themactionfaction.com> wrote:
On Nov 14, 2007, at 1:37 PM, Nick Zitzmann wrote:
I searched around and didn't see anything relevant...
In our 32-bit projects, we're calling:
srandom(time(NULL));
What's the best way of doing something like the above in a 64-bit program? srandom() takes a 32-bit integer when compiling for both 32-bit and 64-bit, but time() returns a 64-bit integer when compiling for 64-bit. I guess I have until 2038 to worry about this, but I'd rather deal with it now...
srandrom() doesn't really care about the actual time- you should just make sure you seed with the least-significant 32-bits which you can
Because of the type conversion rules of C, you're guaranteed to get the least significant 32-bits when you convert a 64-bit unsigned integer to a 32-bit integer. No need for any bitwise operations.: unsigned seed = time(NULL); -- Clark S. Cox III clarkcox3@gmail.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com