开发者

What is the exact algorithm for Objective-C's built-in rand() function?

开发者 https://www.devze.com 2023-02-05 20:29 出处:网络
If you have a client/server application and you want to duplicate the same series of random numbers that the rand() function produces on the client, but on a server, what is the algorithm/pseudo code?

If you have a client/server application and you want to duplicate the same series of random numbers that the rand() function produces on the client, but on a server, what is the algorithm/pseudo code? The client and server would be given the same seed (srand() on the client).

Thank you!

Please note:

  • Is this not known? If so, please state
  • Can it be reverse engineered? If so, please post, unless any license agreements would prevent you from doing so. In other words, don't do anything illegal
  • I am not interested in design suggestions for the client/server applicatio开发者_StackOverflow社区n
  • I understand that there are better and more recent ways to generate rand numbers


From Apple's Darwin source code, here is the Mac implementation of rand(), which should be the same as the one used on iOS. Here also is the random() implementation. They both appear to be drawn from FreeBSD.


Most C compilers I've seen use a linear congruential random number generators for their rand() function. You don't need to reverse engineer it: it's open source.

BTW if this is the basis of some sort of encryption/security system. It's a really bad idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消