Questions tagged [random]
This tag is for questions dealing with random numbers, pseudorandom numbers, and computer entropy.
125
questions
1
vote
1
answer
104
views
Random Numbers and Collisions [closed]
I read a question about using a 32bit random number as a "unique" identifier. One of the answers asserted that a "rough guide" to estimating collision likelihood is that there's a ...
-1
votes
0
answers
21
views
Random selection based on weightage and previous history
I have a spring boot application for a notification system. Consider sms notifications for which I have n vendors to select from. Every vendor has been promised a certain percentage of our business, ...
2
votes
3
answers
1k
views
Is checking if a new GUID exists before insert a code smell?
Say I use GUIDs as keys. Considering the chance of a duplicate GUID being generated being what they are, is code like this considered a code smell?
Guid newID = GenerateGuid();
while (dictionary....
0
votes
2
answers
553
views
What are the reasons not to use random values in unittests? [duplicate]
I've read the questions regarding the use of random values in unit-tests and, well, I still don't quite understand what the argument against random values is.
I'm trying to understand because I've had ...
0
votes
0
answers
259
views
Improving performance of 'Weighted/prioritized left shuffle algorithm'
I wrote a prioritized/weighted left shuffle algorithm (the code is copied from my open source C# project Fluent Random Picker).
What does that mean? You've got some values and each of them has a ...
3
votes
3
answers
528
views
How does cuRAND use a GPU to accelerate random number generation? Don't those require a state?
My understanding is that every PRNG or QRNG requires a state to prevent the next item in its sequence from being too predictable; which is sensible, as they're all running on deterministic hardware.
...
-1
votes
2
answers
225
views
How random is enough to be random? [closed]
I download the atmospheric noise data from random.org in form:
10111011 01101111 01100001 00001001 00100110 10111011 01110110 11010110
00000111 01111110 10001110 01101010 11100000 11110111 10101011 ...
-4
votes
1
answer
77
views
How to write a sporadic metronome?
I already asked this question on stackoverflow -- I am posting it here as well, because I think many of you will have encountered an analogous problem. I would appreciate even a link as a reference, ...
1
vote
4
answers
1k
views
Is using multiple UUIDs decrease chance of collisions exponentially?
For example if you have a single UUID with a collision probability of x, if you concatenate 2 UUIDs, does the collision probability become x^2?
val0 = generate_uuid()
val1 = generate_uuid()
final_val ...
0
votes
3
answers
796
views
How to guarantee an ID is unique in a non-UUID set of values?
I would like to have IDs of different sizes from the alphabet 0-9. So I have 5-length IDs as in 10000 or 13531, etc.. I have 10, 15, 20, up to 39 digit strings (the size of a UUID). I would like to ...
2
votes
3
answers
769
views
Algorithm for random weighted boolean shuffles?
I don't exactly know how to phrase the thing I'm searching for in a succinct way, which also made it hard to research.
In my application I need a random list of booleans, say of length five. The ...
3
votes
3
answers
528
views
Is it really more difficult to debug randomized algorithms?
I am a theoretical computer scientist. I have heard the following:
Practitioners do not like randomized algorithms because they are notoriously difficult to debug. So deterministic algorithms are ...
0
votes
2
answers
116
views
Is it possible to transfer data with a really unique seed of a psudo random number generator
I have thinking about this idea for over 5 years and i don't have the complete technical knowledge to fully grasp the idea I'm having.
The premise of the idea is to have an extremely high base number ...
0
votes
3
answers
306
views
Getting random yet consistent data for testing
I have a big codebase yet to be covered with tests and rather limited access to the real data.
The code that needs to be covered is very data dependent. And the data is anything but shallow and ...
1
vote
2
answers
941
views
How to shuffle a large data set without touching every row?
Let’s say I have two larges arrays of users with equals number of rows and I want to match them randomly and one to one(one from the first array,one from the second), I will first need to shuffle one ...
-1
votes
1
answer
319
views
Choosing random cards from a deck?
Is there a difference between the 2 below methods for choosing a random card from a deck of cards? Is one approach more accepted than the other?
Method 1: Generate a random number from 1-52 for the ...
2
votes
4
answers
570
views
Unit testing Markov chain code
What are the best ways to unit test code that outputs random sequences satisfying specific conditions, such as Markov chains?
Let's be specific. There are two natural things to test:
That the ...
4
votes
2
answers
3k
views
Shuffle in music players
I always hear how it is hard to implement shuffle algorithms for music players, but never really the explanation for it. What makes it hard?
Take for example how I would implement one:
First the ...
-1
votes
1
answer
2k
views
Generating billions of Unique random number [closed]
I recently attended an interview. In that I had to solve the issue for generating an billions of random unique number.
For example method signature is as below :
public Iterator<Long> ...
2
votes
3
answers
308
views
Are all pseudo randomly generated numbers within a given period unique?
This will of course depend on the algorithm generating the pseudo random numbers, but what I'm wondering is whether practical, usable pseudo-random number generating algorithms exist that never repeat ...
2
votes
3
answers
869
views
Can functional programming used for solving problems which require randomness?
This older question tells us that in functional programming "true" randomness cannot be achieved since in FP functions are pure/idempotent and return the same value irrespective of number of ...
0
votes
1
answer
219
views
How to test this getRandom() method? [duplicate]
There are strings and each string has a weight in a data structure. The getRandom() method should return a string randomly with its weight/total weight probability.
There is already a question on how ...
7
votes
4
answers
33k
views
Testing a function that uses random number generator
I have a method which is a part of the interface I am implementing. This method calls another private method which uses a random number generator to produce output and returns it to the calling method....
0
votes
1
answer
312
views
Find Randomized Sequence Seed To Compress files statistically
I was wondering if what I have in mind already exists in any known compression programs/algorithms or not. We know that Seed gives us constant sequence of random numbers. so if we be able to find seed ...
2
votes
2
answers
761
views
Test Driven Development for Stochastic algorithms?
this is similar, but no the same as this post, which was the closest question I could find on this. I don't even see that answer as satisfactory for the question asked in that thread let alone TDD. ...
1
vote
2
answers
101
views
Disk file structure for large string list with fast reads by index
I have large list of strings. Each string is of different length, just like sentence in text. Average length is below 255 chars.
Please, propose file structure on disk to enable fast picking of random ...
1
vote
3
answers
219
views
Randomly sorting a list where some states are illegal?
I want to make a randomizer for the items in the game La-Mulana. However, some arrangements of items would mean that the game cannot be completed. Sometimes there's only one group of items required to ...
5
votes
4
answers
816
views
How to generate a random bag of positive integers that sum up to an input number?
A number N and a range a to b will be input by the user, with a < b < N.
The program purpose is to generate random sets of positive integers that sum up to N, with each positive integers within ...
0
votes
1
answer
801
views
Flowchart: get values from functions. Rectangle or Paralellogram
I need to create a flowchart for one of my algorithms and one step is calling a function (that I don't wish to explain in the flowchart) and assigning the returned value to a variable.
float x = ...
5
votes
2
answers
291
views
Is a random sample from a range of uniformly distributed values still uniformly distributed?
Let's say I have a random number generator from which I am requesting values for event A and event B. Both events occur at random intervals but event A happens much more often than event B and I would ...
2
votes
3
answers
1k
views
Programming a Truly "Fair" Weighted Random Dice Roll
I'm trying to devise a way to create a 'loot table' for an RPG, mostly to see if it can be done.
I'm partly inspired by old D&D style tables, which would list a range of values for each item on ...
0
votes
1
answer
128
views
Return random item by its weight, advanced level
There are many typical questions like Return random `list` item by its `weight`
Imagine more advanced problem.
You have N sources of pair (item_id, weight) information. Let's call them Shards. ...
4
votes
2
answers
4k
views
Generate a unique random 4 digit number from another 4 digit number
I have a database that has two columns. The first column is an index, the second is the path to a data file. There are two types of data files, X and Y. These data files are then processed and graphs ...
-1
votes
1
answer
108
views
How would you explain or visually show someone the difference between linear/static probability vs dynamic?
Forgive me if I'm using the wrong terminology, but I'm attempting to explain to a non-technical person the difference between something happening in a program due to either a Math.Random (seed PRNG) ...
2
votes
2
answers
227
views
Identifying and understanding this PRNG
I have this random number generator, and have had it for quite some time, but despite how much I use it I don't really understand it.
public static int Random(int x)
{
x = x + seed;
x = (x &...
-3
votes
1
answer
112
views
What does set.seed(any number) command means? [duplicate]
I am currently studying R. While studying that I came across a command set.seed(any number) . After googling also I didn't understood much except that it has something to do with Random number ...
4
votes
3
answers
166
views
Restricted randomization of a binary vector
Suppose I have a binary vector of sample size N with each of the two possible values (e.g., 0 and 1 occurring equally often).
For example, if N=10, the binary vector is: 0 0 0 0 0 1 1 1 1 1
Suppose ...
8
votes
1
answer
2k
views
Exclusive upper bound in random number range
Why do languages' random number generators tend to return a value exclusive of the upper bound of the range?
For example, an implicit range -
JavaScript's random() method "Return a random number ...
1
vote
2
answers
116
views
If the size of a set exceeds the period of a PRNG, is it true that some combinations may be unable to be generated? [duplicate]
Given that the size of some sets (example, 52! (about 2226 or 8*1067), the number of ways to shuffle a regular deck of cards) exceeds the period of most Pseudorandom Number Generators (PRNG), is it ...
2
votes
1
answer
104
views
Mechanisms to ensure distributed systems do not sychchronize (anti-synchronize)
We have a service that based on a local timer does a GET request to our server on Azure to transmit some information to be saved on the server. At this stage we are only testing and we are finding ...
0
votes
0
answers
46
views
Pseudorandom in Android
I am building a security mechanism and I need a Pseudorandom functionality in my app. More particularly I need to convert a String to fix length.
My strings are random already, they just to long so I ...
0
votes
2
answers
472
views
What is a readable algorithm for selecting a random buyer based on what they purchased?
I am working on a giveaway algorithm to select a customer based on what they purchased:
If they purchase item 1, they gain 1 point.
If they purchase item 2, they gain 2 points.
If they purchase item ...
6
votes
2
answers
5k
views
Why do we need a seed in Random Number Generators?
I want to know how Random number generator(RNG) works in any PL(Programming language).
I know the random methods has short periods. i.e they start repeating the values after specific number of time.
...
2
votes
1
answer
2k
views
Inclusive or exclusive upper bound in pseudo-random number generators
I am creating a little randomization library. One of the methods is similar to .NET's System.Random.Next(int start, int end). The thing is, I am not sure how to decide on whether the upperp bound ...
2
votes
2
answers
549
views
Shuffle/Randomize a collection without knowing the number of items? [closed]
Let's say I have a sequence of items of unknown length, n. I want to randomize the order of this sequence without having to go through the entire sequence. Are there any algorithms that can do this?
...
9
votes
4
answers
11k
views
rand() gives same numbers again for a small range
I'm trying to make sort of a game where I have a a grid of 20x20 and I display a player (P), a target (T) and three enemies (X). All these have an X and a Y coordinate which are assigned using rand(). ...
4
votes
3
answers
770
views
How to pick a random move/action/element non-probabilistically?
I am trying to create a simple AI that can play Go using Monte Carlo Tree Search.
This question, however, is valid for all games where players take turns doing some action that, on average, reduce ...
3
votes
3
answers
6k
views
Big O notation of randomness
I was thinking about inefficient algorithms based on randomness and wondered how to categorise them.
For instance. Say you wanted to generate all the numbers from 1 to N in a random order but only ...
1
vote
3
answers
350
views
Generate random numbers with certain spikes? [duplicate]
I am trying to generate random numbers to simulate steering wheel angles and velocities of a car. So for steering wheels the random numbers could go like 1,2,4,6,4,3,40,0.
I can generate random ...
3
votes
1
answer
535
views
Should changes to FNV-1A's input exhibit the avalanche effect?
This is kind of related to Which hashing algorithm is best for uniqueness and speed?. In that question, the excellently written top answer notes,
Randomnessification
The other subjective ...