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
7
votes
0answers
134 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 ...
6
votes
0answers
75 views

Perl gradient noise generator

I'm working on 2-D top-down graphics engine, and need a way to simulate clouds. My idea was that I could create a layer comprised of a matrix of rectangles whose alpha value would be picked from a ...
6
votes
0answers
287 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 ...
5
votes
0answers
500 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 ...
4
votes
0answers
72 views

Estimate area of cropped circle with Monte Carlo

I looking around and not finding anything, I developed a simple function for estimating the area of a possibly cropped circle inside a frame. It uses a very basic MC implementation. It is pretty fast ...
4
votes
0answers
66 views

Logarithmic random distribution satisfying RandomNumberDistribution concept

I provide logarithmic_distribution to satisfy the C++ RandomNumberDistribution concept implementing the PDF ...
3
votes
0answers
22 views

Random generation java logic used in Nifi

I was just reviewing the source code of Nifi, see explanation and public version of the source. This got me wondering whether there are any obvious improvements here to increase the performance of the ...
3
votes
1answer
75 views

Randomizing all class variables in constructor c++

I'm playing around with making random items and decided to implement the following structure. ...
3
votes
0answers
22 views

Optimization of weightedWinner() and random() function

I have written a Lottery contract that picks winner based on the amount they contributed to the pool. I am looking if the code of weightedWinner function can be ...
3
votes
0answers
71 views

Probability shooting game

I've been working on this probability game that has a gun with 5/6 bullets. When there's a dodge the game removes a bullet and then the game continues, the goal being to get to 0 bullets. I don't ...
3
votes
0answers
51 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 ...
3
votes
0answers
105 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 ...
3
votes
0answers
147 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 (...
3
votes
0answers
146 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: ...
3
votes
0answers
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 ...
3
votes
0answers
68 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 ...
2
votes
0answers
223 views

JavaScript random BigInt

Problem: JavaScript does not provide a random BigInt so there is a need to generate a random BigInt within a given range that is evenly distributed. Solution I have tried many algorithms with a ...
2
votes
0answers
62 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 ...
2
votes
0answers
734 views

Thread-safe rand for C

I have this very short program for dealing with thread-safety of C's rand. Is it a correct implementation? ...
2
votes
0answers
92 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 ...
2
votes
0answers
611 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. ...
2
votes
0answers
41 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 ...
2
votes
0answers
489 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 ...
2
votes
0answers
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: ...
2
votes
0answers
145 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++ ...
1
vote
0answers
56 views

Generate random letters containing a word

There is a popular game called 4 Pics 1 Word that presents to the user 4 pictures representing a common word. The word has to be typed by selecting some of the 9 random letters appearing below the ...
1
vote
0answers
36 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 ...
1
vote
0answers
132 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 ...
1
vote
0answers
385 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 ...
1
vote
0answers
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 ...
1
vote
0answers
200 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 ...
1
vote
0answers
783 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 ...
1
vote
0answers
97 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 ...
1
vote
0answers
83 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 ...
1
vote
0answers
333 views

Seeded array shuffle

This should be relatively simple, but I want to know if I've done the randomness bit correctly. ...
1
vote
0answers
200 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 ...
1
vote
0answers
106 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 ...
1
vote
0answers
231 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 ...