Questions tagged [random]

This tag is for questions pertaining to random numbers and their generators, whether pseudo-random or truly random.

This tag is for questions pertaining to creating random numbers or random distributions: using random number generators (RNGs), creating specific distributions (e.g. Gaussian, Bernoulli or log-normal) with given parameters from normal random numbers, problems and caveats with given implementations in different languages.

Since different languages may use different RNGs, a question with this tag must also be tagged with the language being used.

Frequently-asked questions

  • How can I generate N uniformly-distributed random real numbers that sum to a given value?

  • How can I choose N elements, avoiding duplicates, from a list (or from the integer range 1..M)? This is known as dealing elements, as in dealing playing cards.

  • If I create a new random number generator object for each request, why does it return the same value repeatedly? (Or: only seed the random generator once)

  • How do I generate a random integer value within a range?

35221 questions
10
votes
4 answers

Java Generator for Poisson and Uniform Distributions?

From what I understand, the standard generator is for the Normal Distribution. I have to generate random numbers according to the Normal, Uniform and Poisson Distributions, but I can't seem to find a class for the last 2. I have to generate them in…
master cheif
10
votes
2 answers

How to locally unit-test Chainlink's Verifiable Random Function?

Context While trying to set up a basic self-hosted unit testing environment (and CI) that tests this Chainlink VRF random number contract, I am experiencing slight difficulties in how to simulate any relevant blockchains/testnets locally. For…
a.t.
  • 2,002
  • 3
  • 26
  • 66
10
votes
10 answers

math random number without repeating a previous number

Can't seem to find an answer to this, say I have this: setInterval(function() { m = Math.floor(Math.random()*7); $('.foo:nth-of-type('+m+')').fadeIn(300); }, 300); How do I make it so that random number doesn't repeat itself. For example if…
daryl
  • 14,307
  • 21
  • 67
  • 92
10
votes
2 answers

How (if at all) does a predictable random number generator get more secure after SHA-1ing its output?

This article states that Despite the fact that the Mersenne Twister is an extremely good pseudo-random number generator, it is not cryptographically secure by itself for a very simple reason. It is possible to determine all future states of the…
emboss
  • 38,880
  • 7
  • 101
  • 108
10
votes
9 answers

get random value from a PHP array, but make it unique

I want to select a random value from a array, but keep it unique as long as possible. For example if I'm selecting a value 4 times from a array of 4 elements, the selected value should be random, but different every time. If I'm selecting it 10…
Alex
  • 66,732
  • 177
  • 439
  • 641
10
votes
5 answers

Pseudo-random number generator for cluster environment

How can I generate independent pseudo-random numbers on a cluster, for Monte Carlo simulation for example? I can have many compute nodes (e.g. 100), and I need to generate millions of numbers on each node. I need a warranty that a PRN sequence on…
Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
10
votes
4 answers

Java Random, little change in seed causes only little change in output

While making a map generator in Java I found a rather unnerving problem with their random number generator, to specify, when two RNGs have very similar seeds (differing in small integers) their first output value will become very similar! Example…
Szoltomi
  • 193
  • 1
  • 10
10
votes
1 answer

How is numpy.random.Generator different from RandomState?

Generator sounds like a replacement for RandomState, and the way of the future for generating random numbers in NumPy. What features or behavior (currently or planned) does Generator have that RandomState doesn't? Both can be parameterized with…
william_grisaitis
  • 5,170
  • 3
  • 33
  • 40
10
votes
2 answers

Weird Random Number Bug In .Net

I'm sure I'm doing something wrong; but this has been driving me crazy for a while now. I've made a small Silverlight game (an old Galaxian clone). When the game starts ~90% of the time, a bunch of stars are randomly positioned in the game area. …
Rob P.
  • 14,921
  • 14
  • 73
  • 109
10
votes
3 answers

Is /proc/sys/kernel/random/uuid strong keying material?

I've been looking at ways to generate a strong 256 bit/32 byte symmetric key for the HMAC_SHA256 algorithm. I stumbled upon the /proc/sys/kernel/random/uuid file. According to man random(4): "The read-only files uuid and boot_id contain random…
pfarber
  • 141
  • 2
  • 5
10
votes
2 answers

Simple way to choose random cell from a list in Google Sheets

Do you have a list of names in one column and want to draw between them? Here is the simplest way to do this.
Digital Farmer
  • 1,705
  • 5
  • 17
  • 67
10
votes
4 answers

Get a random element in single direction linked list by one time traverse

I have a single direction linked list without knowing its size. I want to get a random element in this list, and I just have one time chance to traverse the list. (I am not allowed to traverse twice or more) What’s the algorithm for this problem?…
卢声远 Shengyuan Lu
  • 31,208
  • 22
  • 85
  • 130
10
votes
5 answers

Implementing Box-Mueller random number generator in C#

From this question: Random number generator which gravitates numbers to any given number in range? I did some research since I've come across such a random number generator before. All I remember was the name "Mueller", so I guess I found it,…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
10
votes
2 answers

Arithmetic underflow or overflow exception during debugging

This is the day of weird behavior. We have a Win32 project made with Delphi 2007, which hosts the .NET runtime and calls into .NET to show new forms, as part of a transition period. Recently we've begun experiencing exceptions at seemingly random…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
10
votes
5 answers

windows batch file script to pick random files from a folder and move them to another folder

I need a batch script to randomly select X number of files in a folder and move them to another folder. How do I write a windows batch script that can do this?
techdaemon
  • 215
  • 2
  • 7
  • 13