Questions tagged [random]

This tag is for questions dealing with random numbers, pseudorandom numbers, and computer entropy.

Filter by
Sorted by
Tagged with
-1 votes
2 answers
778 views

Can an 81 digit number generator lead to copyright infringement? [closed]

I'm looking to write a program that will generate valid sudoku puzzles. Essentially, a sudoku puzzle is just an 81 digit number. (The blanks are zeroes.) I would then like to use these puzzles in an ...
35 votes
1 answer
27k views

Original source of `(seed * 9301 + 49297) % 233280` random algorithm?

If you search for examples of creating a seeded (pseudo)Random number generator, you will run into stuff like this (specific example http://indiegamr.com/generate-repeatable-random-numbers-in-js/): //...
4 votes
1 answer
443 views

random.choice in other languages

Python has a nice function in the standard library random.choice which returns a random element from a sequence. But none of the other languages I've developed in have thought to include such a ...
0 votes
5 answers
5k views

Generate unique integer from two integers with algorithm

I am currently trying to come up with an algoritm which would take at least two numbers (say user IDs) and then come up with an unique number which is generated based on these two numbers. Each ...
25 votes
7 answers
14k views

How to generate "language-safe" UUIDs?

I always wanted to use randomly generated strings for my resources' IDs, so I could have shorter URLs like this: /user/4jz0k1 But I never did, because I was worried about the random string generation ...
14 votes
4 answers
1k views

What are best practices for testing programs with stochastic behavior?

Doing R&D work, I often find myself writing programs that have some large degree of randomness in their behavior. For example, when I work in Genetic Programming, I often write programs that ...
2 votes
3 answers
726 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
299 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
211 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 ...
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 ...
58 votes
5 answers
54k views

get weighted random item

I have, for example, this table +-----------------+ | fruit | weight | +-----------------+ | apple | 4 | | orange | 2 | | lemon | 1 | +-----------------+ I need to return a random ...
3 votes
3 answers
320 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
218 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
73 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
638 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 ...
166 votes
11 answers
92k views

How should I test randomness?

Consider a method to randomly shuffle elements in an array. How would you write a simple yet robust unit test to make sure that this is working? I've come up with two ideas, both of which have ...
2 votes
3 answers
701 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 ...
14 votes
2 answers
1k views

Random Cache Expiry

I've been experimenting with random cache expiry times to avoid situations where an individual request forces multiple things to update at once. For example, a web page might include five different ...
3 votes
3 answers
511 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 ...
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 ...
0 votes
2 answers
112 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 ...
45 votes
14 answers
10k views

Unit-testing of inherently random/non-deterministic algorithms

My current project, succinctly, involves the creation of "constrainably-random events". I'm basically generating a schedule of inspections. Some of them are based on strict schedule constraints; you ...
0 votes
3 answers
288 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
753 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
295 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
552 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 ...
-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
303 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
853 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 ...
10 votes
6 answers
11k views

I need a true random number generator web service [closed]

Random.org provides 200k free random bits (only 6250 32-bit integers!) from the analog world (cf.) per IP per day. Does anyone know of an alternative web service that provides more on-demand random ...
5 votes
8 answers
10k views

random generator not good enough?

During an interview I was asked to implement a random generator in java without using any existing random number libraries that takes as an argument int n, and returns a random number between 0 and n. ...
0 votes
1 answer
210 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
31k 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
252 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 ...
1 vote
2 answers
2k views

Is generating a large random number more unique than generating each digit in that number?

I'm using a PRNG (PHP's default rand() implementation) to generate unique 16 digit numbers. Does it make sense to generate digits one by one, or the number at once? I'm using PHP.
4 votes
3 answers
161 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 ...
2 votes
2 answers
718 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
100 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 ...
28 votes
6 answers
116k views

How do random number generators work?

I was just pondering about php rand() function, and thinking about how I could remake it, and I came up completely stupified. How do random number generators work?
5 votes
4 answers
795 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 ...
5 votes
2 answers
290 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 ...
13 votes
2 answers
4k views

Since Garbage Collection is non-deterministic, why isn't it used for secure random number generation?

I get that /dev/random is a good source of entropy, and is what is usually used-- It's just as I'm reading up on GC, at least in Java, it seems accepted that the garbage collection daemon executes non-...
0 votes
1 answer
770 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 = ...
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
127 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. ...
6 votes
4 answers
11k views

How to generate random numbers without making new Random objects?

I'm using this as part of a game, but it's not really a game development question, so I'm putting it on this more general Stack Exchange. The goal is to generate "random" outputs for a fixed integer ...
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
107 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
217 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 &...