[all-commits] [llvm/llvm-project] ef169f: [libc] Improve the implementation of the rand() fu...

Joseph Huber via All-commits all-commits at lists.llvm.org
Tue Sep 12 14:52:34 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ef169f5707075e6f59f2add26333f56376b5ac64
      https://github.com/llvm/llvm-project/commit/ef169f5707075e6f59f2add26333f56376b5ac64
  Author: Joseph Huber <35342157+jhuber6 at users.noreply.github.com>
  Date:   2023-09-12 (Tue, 12 Sep 2023)

  Changed paths:
    M libc/include/llvm-libc-macros/stdlib-macros.h
    M libc/src/stdlib/rand.cpp
    M libc/src/stdlib/rand_util.cpp
    M libc/test/src/stdlib/rand_test.cpp

  Log Message:
  -----------
  [libc] Improve the implementation of the rand() function (#66131)

Summary:
This patch improves the implementation of the standard `rand()` function
by implementing it in terms of the xorshift64star pRNG as described in
https://en.wikipedia.org/wiki/Xorshift#xorshift*. This is a good,
general purpose random number generator that is sufficient for most
applications that do not require an extremely long period. This patch
also correctly initializes the seed to be `1` as described by the
standard. We also increase the `RAND_MAX` value to be `INT_MAX` as the
standard only specifies that it can be larger than 32768.




More information about the All-commits mailing list