1 //===-- Implementation of rand --------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/stdlib/rand.h"
10 #include "src/__support/common.h"
11 #include "src/stdlib/rand_util.h"
13 namespace LIBC_NAMESPACE
{
15 // An implementation of the xorshift64star pseudo random number generator. This
16 // is a good general purpose generator for most non-cryptographics applications.
17 LLVM_LIBC_FUNCTION(int, rand
, (void)) {
18 unsigned long x
= rand_next
;
23 return static_cast<int>((x
* 0x2545F4914F6CDD1Dul
) >> 32) & RAND_MAX
;
26 } // namespace LIBC_NAMESPACE