rand

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequiredSampleSize

func RequiredSampleSize(probability, errThreshold, confidence float64) int64

RequiredSampleSize calculates the number of samples needed to achieve a desired confidence level for a given probability and error threshold. Arguments:

  • probability: the estimated proportion of the population (e.g., 0.5 for 50%).
  • errThreshold: the desired margin of error, which is the maximum acceptable difference between the sample estimate and the true population proportion (e.g., 0.05 for ±5%). A smaller threshold means higher precision, but it requires a larger sample size.
  • confidence: the desired confidence level, which represents the likelihood that the true population proportion falls within the margin of error around the sample estimate (e.g., 0.95 for 95% confidence). A higher confidence level means more certainty, but it also requires a larger sample size.

The function uses the standard formula for sample size determination for estimating a proportion. For more details, see: https://en.wikipedia.org/wiki/Sample_size_determination#Estimation_of_a_proportion

func SeededFloat32

func SeededFloat32(seedParts ...[]byte) (float32, error)

SeededFloat32 generates a deterministic float32 between 0 and 1 given a seed.

TODO_MAINNET: To support other language implementations of the protocol, the pseudo-random number generator used here should be language-agnostic (i.e. not golang specific).

func SeededInt63

func SeededInt63(seedParts ...[]byte) int64

SeededInt63 generates a deterministic non-negative int64 by seeding a random source with the hash of seedParts.

TODO_MAINNET: To support other language implementations of the protocol, the pseudo-random number generator used here should be language-agnostic (i.e. not golang specific).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL