Questions tagged [random]

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

32 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
1 answer
367 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 ...
Theodor Johnson's user avatar
5 votes
0 answers
1k 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 ...
user14717's user avatar
  • 785
4 votes
0 answers
96 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 ...
Gabriel's user avatar
  • 575
4 votes
0 answers
71 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 ...
Iftifar Taz's user avatar
4 votes
0 answers
173 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: ...
Michael Völkl's user avatar
3 votes
0 answers
51 views

Idiomatic PRNG in Scheme

For reasons that are too dreary to detail, I need to reproduce several pseudo random number generators in different languages. It mostly involves translating ancient C and FORTRAN code. No problems ...
clartaq's user avatar
  • 257
3 votes
0 answers
82 views

Async generation of large buffers of random numbers on the GPU

I would like to obtain some feedback on a simple code I wrote to implement an easy and hopefully fast way to generate a large number of floats with CURAND and use them one at a time. This is achieved ...
rng_help's user avatar
3 votes
0 answers
2k 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 ...
Blindman67's user avatar
  • 21.8k
3 votes
0 answers
85 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 ...
bibble triple's user avatar
3 votes
0 answers
56 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 ...
tim-mccurrach's user avatar
3 votes
0 answers
122 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 ...
spydon's user avatar
  • 131
3 votes
0 answers
259 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 (...
ligos's user avatar
  • 173
3 votes
0 answers
139 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 ...
dh16's user avatar
  • 131
2 votes
0 answers
135 views

Truly cryptographically secure password generator in Python, version 2

Following suggestions from answers from my previous question, I have completely rewrote my script, to make it more concise and Pythonic, truly cryptographically secure, and added more functionality. ...
Ξένη Γήινος's user avatar
2 votes
0 answers
59 views

Python: Random forest code optimization

I've been working on random forest algorithm for classification with roulette selection to find best splits. I came up with this homebrew based on this article https://machinelearningmastery.com/...
Doombino's user avatar
2 votes
0 answers
151 views

Creating a simple one-dimension Sobol sequence generator

A Sobol sequence, a series of low-discrepancy quasi-random numbers in range [0,1], can be generated by first initializing a vector of direction numbers: ...
user avatar
2 votes
0 answers
315 views

Python Markov Chain based pseudoword generator

This is a Python 3 module that generates random pronounceable word-like strings based on Markov Chains. It has many modes, each mode conforms to the structures of dictionary words to a degree, the two ...
Ξένη Γήινος's user avatar
2 votes
0 answers
44 views

Randomly generating invoice IDs

As more fully detailed in my question here, I'm in the process of starting a small, local business and wanted to avoid showing sequential invoice IDs to clients, and instead generate completely random ...
Hashim Aziz's user avatar
2 votes
0 answers
88 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 ...
Jose Fernando Lopez Fernandez's user avatar
2 votes
0 answers
1k 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? ...
coderodde's user avatar
  • 28k
2 votes
0 answers
2k 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 ...
Scooby's user avatar
  • 29
2 votes
0 answers
102 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 ...
sator.arepo.tenet.opera.rotas's user avatar
2 votes
0 answers
689 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. ...
kr099's user avatar
  • 151
2 votes
0 answers
43 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 ...
jalapic's user avatar
  • 143
2 votes
0 answers
629 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 ...
Qiri's user avatar
  • 141
2 votes
0 answers
147 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++ ...
MORTAL's user avatar
  • 3,278
1 vote
0 answers
61 views

simulation of updating a dataset from real time data

In this code (reproducible example) I want to generate a dataframe composed by random dates in the first col, and by random numbers (in reality they will be generate from a socket) in the second ...
Carlo's user avatar
  • 111
1 vote
0 answers
87 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 ...
Roland Illig's user avatar
  • 21.3k
1 vote
0 answers
771 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 ...
Rakka Rage's user avatar
1 vote
0 answers
916 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 ...
Stepan Vanzuriak's user avatar
1 vote
0 answers
227 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 ...
sator.arepo.tenet.opera.rotas's user avatar
1 vote
0 answers
276 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 ...
Vlastimil Burián's user avatar