# Questions tagged [random]

This tag is for questions pertaining to random numbers, whether pseudo random or truly random.

669 questions
Filter by
Sorted by
Tagged with
88 views

### Generate a sequence of coin flips until pattern is hit

A book on probability says that a sequence of heads and tails is generated by a fair coin asking what is the probability that the pattern T, H, H, H occurs before the pattern H, H, H, H. I have made a ...
2k views

### Generating text from a Markov chain in Java

I have this small program that constructs a Markov chain from Tolstoy's War and Peace and allows the user to play with it by generating sentences of variable length in words. MarkovChain.java ...
365 views

### Perlin Noise terrain in Unity3D

I've recently had time to devise another program so this time I decided to write the Perlin Noise algorithm in code. I have succeeded and the code works but I can't help but feel that my practices ...
494 views

### Python - Random Number Guessing Game

I'm new to programming in general (Python is the first language I've tried learning) and I'm working my way through a collection of beginner's challenges. I'm having a little trouble wrapping my head ...
2k views

### Randomly pick a first name from a file

I have a very easy question for you guys out there. It's been a while since I took my programming courses (switched majors) but am trying to get my feet wet again. Objective: I will be creating a ...
101 views

### Selecting random class from weighted class probability distribution

I have a solution that I've scratched out, but it's a tad messy: First, let's say we have a random number from a uniform distribution we'll be using to select a random class from a class probability ...
816 views

### Generate random letter by frequency

Which method below should I use to generate a "random letter by frequency" using Javascript? From https://gist.github.com/furf/2413792 ...
1k views

### Pseudo Random Number Generator

I recently watched this video about the random number generation in Super Mario World. The technique that is used, as seen in the image below, multiplies one of the seeds by 5 and adds 1, the other ...
656 views

### Random range with no repeat and efficient for small subset

Random range with no repeat and efficient for small subset. But still survives if return most or all. This comes up poker simulation as you typically only deal 1/3 the deck. The idea is to use ...
983 views

### Iterator producing unique random numbers in a specified range

I needed an iterator that produced random numbers, never repeating them, in a specified range of 0..max-1 (index for a collection). When the numbers are exhausted it should not have a next anymore. ...
62 views

### Logarithmic random distribution satisfying RandomNumberDistribution concept

I provide logarithmic_distribution to satisfy the C++ RandomNumberDistribution concept implementing the PDF ...
137 views

### Implementation of logarithmic random distribution satisfying RandomNumberDistribution concept

Following from this post on SO, I provide logarithmic_distribution to satisfy the C++ RandomNumberDistribution concept implementing the PDF ...
1k views

### Generating Uniformly Distributed Random Numbers

Edit: Dunno what PCG is and don't want to read the paper? Maybe this video of Melissa O'Neill (the author) explaining things will be palatable instead. Original: I attempted to answer this question ...
685 views

### Monty Hall simulation with any number of doors

After answering Monty hall python simulation I wondered what the outcome were to be if there were more than three doors, say four or seven. And so I decided to modify the problem slightly to adjust ...
6k views

### C++ Coin flip simulator and data collector

Asks the user for the chance of a coin landing on heads, the number of trials per experiment, and the number of experiments. For example, given 5 trials per experiment and 20 experiments, the program ...
4k views

### Generate cryptographically secure random numbers in a specific range

A project I'm working on requires generating a random number of $N$ length to a very high degree of fair distribution between digits $[0, 9]$. That said, I used the ...
129 views

### Random number generation

I'm trying to port some MonteCarlo code to CUDA (this is my first CUDA experience). The CPU code often calls a function which generates a random number: ...
730 views

### Infinite monkey theorem demonstration in Python

This was the assignment: Here’s a self check that really covers everything so far. You may have heard of the infinite monkey theorem? The theorem states that a monkey hitting keys at random on ...
767 views

### Monty hall python simulation

I have the following code that simulates the monty hall problem (see google for more details). I used sets to do it but is there a more intuitive or efficient way to do it? ...
230 views

### Helper method to shuffle cards list for online gaming

I have written this code to shuffle a deck of cards. I would like to hear your inputs. ...
655 views

### Powerball Lottery Simulator in C

I made a Powerball lottery simulator in C. I chose C because it is fast. Here's how it plays: The user plays one ticket every day. The user can choose to play the same ticket every day or a ...
70 views

### Testing a chance-based class

So, chance, huh? Randomness. I'm looking into how I can test a class whose sole responsibility is to return weighted random results, that is, where there is a set probability of returning true. The ...
287 views

### Given a function that returns a random number 0 or 1, write a function that returns a number between 0 and 199

We are given a function f2(), that can return either 0 or 1 with equal probability. Now ...
3k views

### Uniform random numbers in an integer interval in C

I need to generate random integers inside a range [a, b] in C. I used the normal implementation that you will see everywhere on the internet and wrote the following: ...
16k views

### Generate 16-digit unique code (like product serial)

I am not sure what to call this type of code (16-digit alphanumeric code). Conditions are like this: Digits (or characters) are limited 16 Numeric, alphabet mixed No duplication allowed (not yet ...
79 views

### Conditionally selecting random element from array

I'm building a clone of 2048 in C with SDL2, and I'm implementing the function that adds a number randomly to an empty cell on the board. The board is representd by a 2-Dim array ...
1k views

### Simple hashing and salting algorithm

I have devised what I feel to be a simple hash/salting algo for Java, and am looking for some feedback from people more skilled than myself. Please find below my code; ...
166 views

### A Random Insult Generator (i.e. a Tree class for generating random sequences of elements)

I made a generic tree class, which is meant to be useful for generating random sequences of elements, for example, sentences (sequences of strings). Also, I have some concernings regarding the tree's ...
367 views

### Simulated arcade with a slot machine and number-guessing game

I am creating an arcade type thing in Python. Could someone suggest ways to simplify this code, or any other tips? All help is much appreciated. I think the ...
560 views

### NCAA Pool - Generate random teams for a list of players

Anyways, I am running a pool where 64 entrants will receive a random team from a field of 64 teams. I'd like for it to be randomized to a decent extent, and although I understand the limitations of ...
3k views

I'm pretty new to Python and I made a password generator. I would like you to check it out and give me tips on how I could do it better. ...
401 views

### Sampling words from randomly chosen text files

I've developed a script to randomly select 50 elements from a list of .txt files. This process is repeated 100 times. The script joins the randomly selected text files to one long string and then ...
200 views

### Resizing a discrete uniform CSRNG distribution

I have a requirement to generate a uniform distribution of cryptographically secure random numbers. To generate these numbers I only know of the ...
2k views

### Python name generator

This is a basic name generator I just wrote and want some feedback. It basically chooses between a vowel or a consonant and appends it to a string. Note that it never puts two vowels or two consonants ...
417 views

### Node.JS Automatic Poem Generator

As a simple programming exercise, I wrote a piece of Node.JS code which generates random poems. It is based on a list of articles (kind of), nouns, linking verbs, and adjectives. It then combines them ...
692 views

### Random MP3 Selector and Player

So, I am either a glutton for punishment, or I have no life, but I wrote a script to answer a question over on Ask Ubuntu as a solution for selecting a random MP3 file in a given directory, and ...
130 views

### Generate new latitude and longitude in decimal

I have created simple algorithm to generate the new Location from given latitude and longitude. ...
2k views

### Generate random and unique array of int values for a given size

I need to generate an array of int values for a given size, the values should be random and unique. the following implementation is "ok" for small values [1,10k], I ...
83 views

### JavaScript constructor function “RandomNumbers”

My idea is to have objects which contain random numbers. The random numbers are keeped in some data structure (within the objects). Furthermore the objects shall have methods for working with the ...
404 views

### Generating bounded & unique random numbers in the Linux kernel

I recently needed to generate a series of unique random numbers (non-repeated) within a bounded range inside of the Linux kernel. The code I came up with is below. I'd appreciate any feedback -- again,...
1k views

### KS-Statistic in C++

Consider the MCG with parameters: a = 23, M = 10^8 + 1, and let the seed be 47594118. (This is the original MCG proposed by Lehmer in 1948.) Apply the Kolmogorov-Smirnov test to the first 1000 random ...
3k views

### Python election challenge

Basically, there is an election on 3 regions where either candidate needs to win 2 in order to win the election. Idea is to simulate 10000 elections to see which candidate wins. I think my solution ...
98 views

### Random Number Generator from user touch input

I have this in place for an RSA Key generation class. I force the user to swipe on the screen randomly and use that as a entropy pool. ...
394 views

My use case is I want a password generator that generates memorable and robust passwords for users, to give me a known minimum entropy. For this - I'm approximating set of Consonant-Vowel-Consonant ...
103 views

### Compression unit test data “easy case”

In another post I created a piece of data, which make compressor annoyed. Create 'worst case test' data for compression test Now I am trying to make it happy. I generate another data set, ...
711 views

### Display four random entries from an array

This code will take the array shown and display 4 random entries in the format shown (or near enough). Are there any parts of this that can be optimised? I'm not happy about the ...
115 views

### Custom UUID based on time

I've been using random UUIDs—from Rust, e.g. Uuid::new_v4()—for my primary keys in a MySQL database. I recently happened across this, which suggests ...
9k views

### Random string of variable length generator

Below is my code for generating a random string of random length. I am using it in integration tests. Currently I have almost 2000 tests running each time a commit is made to master and a few of those ...