github.com/nats-io/nats-server/v2@v2.11.0-preview.2/internal/fastrand/fastrand.go (about)

     1  // Copyright 2020-2023 The LevelDB-Go, Pebble and NATS Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package fastrand
     6  
     7  import _ "unsafe" // required by go:linkname
     8  
     9  // Uint32 returns a lock free uint32 value.
    10  //
    11  //go:linkname Uint32 runtime.fastrand
    12  func Uint32() uint32
    13  
    14  // Uint32n returns a lock free uint32 value in the interval [0, n).
    15  //
    16  //go:linkname Uint32n runtime.fastrandn
    17  func Uint32n(n uint32) uint32
    18  
    19  // Uint64 returns a lock free uint64 value.
    20  func Uint64() uint64 {
    21  	v := uint64(Uint32())
    22  	return v<<32 | uint64(Uint32())
    23  }