# Questions tagged [random]

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

38 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2k views

### Inverse transform sampling

Inverse transform sampling is a method to generate random values that follow an arbitrary distribution. For some reason this method was never implemented in any popular scientific libraries. And as I ...
91 views

### Metropolis Monte Carlo Sampler in Rust

the following is an implementation of the standard Metropolis Hastings Monte Carlo sampler. You can read more about it here. At the end I am going to give you a link to the Rust playground, so you ...
351 views

### Quasi-Random Number Generators

I would like to communicate a piece of code which I hope will soon be broadly useful for everyone who programs in C++: A set of quasi-random number generators proposed for addition to boost.random. To ...
276 views

### Better rand() API

I use this document as a basis for my mini-library: Motivation The std::rand friends are discouraged in C++14, so we want: A direct replacement to ...
51 views

### Node secure randomness implementations

I'm trying to generate secure randomness in Node as a personal challenge. I was wondering if the following implementations are correctly random or they have some flaws. ...
61 views

### Logarithmic random distribution satisfying RandomNumberDistribution concept

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

### Quiz for random boolean expressions

Inspired by the various quiz programs on this site, as well as Simon Tatham's puzzle collection, I thought I'd write a quiz that constructs its questions automatically and randomly. A typical session ...
50 views

### 'Weighted sample' from overlapping categories

I wish to write a function, that will sample from various (potentially overlapping) categories $C_1, C_2, \ldots C_k$, such that the sampled values are in the ratio $r_1:r_2:\ldots: r_k$ or as ...
128 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: ...
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 ...
40 views

### Java Perlin noise implementation

I've decided to code Perlin noise generator in Java. It works pretty well, I just want to know If I am doing everything right and if it is a valid implementation! PS : The ...
35 views

### Random password generator with choice of three strengths

My code works fine but I definitely have unecessary repeat code. I'd like to use functions so I don't have repeat code. I would appreciate any advise on how to make my password generator code more ...
43 views

### Password Generation Using Cryptographically Strong Random Number Generation

My goal in creating this project was to create a password generator that was simple enough to be useful as well as sophisticated enough in its random-number generator so as to not be contrived. I ...
96 views

### Filling up a hand with random cards that are not yet drawn - Monte Carlo

I would like to know if there is a more efficient way to speed up below code. This function is meant to fill in a set of poker hand with the remaining cards using Mersenne Twister for a Monte Carlo ...
587 views

I have this very short program for dealing with thread-safety of C's rand. Is it a correct implementation? ...
99 views

### Recursive Blum Blum Shub

Since my last tattoo resulted in a syntax error I was thinking of getting it peer reviewed this time around, are there any errors or quirks with this recursive Blum Blum Shub implementation that I ...
115 views

### Correctness of PRNG / DRBG from Fortuna - C#

I'm writing a C# implementation of Fortuna, and have implemented the core PRNG / DRBG which should produce a uniform distribution. I've run a variety of statistical random test suites over the output (...
88 views

### Multithreaded Monte Carlo pi approximation with own pseudorandom number generator - follow up

This is a follow up of the question I posted previously here. I made some changes, based in the answer by MikeMB, making use of asynchronous calls (with std::async ...
55 views

### Closest points using Rabin randomizing approach

I was told to use the following Rabin algorithm to find the shortest distance between 2 points in 2D: Randomly choose sqrt(n) and brute force to find the closest ...
527 views

### Random quote machine with jQuery

I've done a random quote machine in jQuery. Could you look at the code and propose some improvements (especially jQuery code)? Here's the working app. ...
40 views

### Generate sample of permuted sequences with non-repeating elements

I have a very long sequence of letters (>20000 elements long). I want to permute them so that I have another sequence using the same letters but in a different order but still with the property of no ...
415 views

### PHP Lottery Simulator

I have a lottery simulator on my website that simulates you playing the lottery every week until your death and tells you how much you would have won or lost. It can take a custom number of balls and ...
59 views

### Calculating all combinations to make sure a Random algorithm has done them all

I have done this, but it's pretty ugly and it feels like I may be missing something to shorten it: ...
142 views

### Generate a random numbers class - follow-up

Previous question: Generate a random numbers class I have come up with three different ways to define type of mUniformDistribution. All of them work fine in VC++ ...
32 views

### Moderate return-low risk vs high returns-high risk investments

To quantify Buffet's #1 rule of investing, "Don't lose money", I take the assumption that % returns of an investment follow a Normal distribution. Now a high return high risk investment might follow ...
126 views

### Simple joke guessing game

Based on the many other number guessing games people tend to post as first questions, https://www.xkcd.com/221/, and a crypto class I'm taking, I've decided to implement a number guessing game using ...
204 views

### Unity Tilemap RandomBrush with orientation and probabilities and fixes

Unity3D.com recently released a 2-D Tilemap system. It comes with a really basic RandomBrush for painting a random tile from a list of tiles. But the tiles were not being saved between preview and ...
33 views

### Bat file that can create a text file of any exact size and it will be compression resistant

I'm making a bat file that can create a text file of any exact size and it will be compression resistant just for fun. It's currently in 2 parts because that's the only way I could figure out how to ...
114 views

### GLSL Simplex Noise with derivatives

I recently made 2d simplex noise based coherent noise in GLSL. [Here] is the shader toy. I wanted to make an implementation of simplex noise on the gpu in order to get better performance than the CPU ...
626 views

### NodeJS Random sentence generator using Markov chain

Program generate sentences using Markov model and 3 text files Text file example: Antoine de Saint-Exupery, who was a French author, journalist and pilot wrote The Little Prince in 1943, one ...
95 views

### Random number distribution program

I'm moving outside my comfort zone and trying to make a random number distribution program while also making sure it is still somewhat uniform. I was trying to generate this in debug mode without ...
81 views

### A Simple Cluster Generator v0.32

This is a code revision of a previous post and works well. The purpose of this code is to produce a universe of points, randomly generated around predetermined centroids, provided from the user as ...
279 views

### Seeded array shuffle

This should be relatively simple, but I want to know if I've done the randomness bit correctly. ...
162 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 ...
95 views

### Einstein's Riddle via simulated annealing in Rebol

This solves Einstein's Riddle via simulated annealing. Rebol translation of Python example by Anojh Gnanachandran at his blog. It gives the correct answer when it doesn't time out, in about same ...
216 views

### Password Entropy in Lazarus (Delphi-like)

My today's goal was to create a function, which would evaluate the entropy of a given string password. It's mostly about how random the password is. This little code is based on the C# code from Jeff ...