Questions tagged [random]

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

Filter by
Sorted by
Tagged with
6
votes
1answer
74 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 ...
0
votes
1answer
140 views

POSIX shell script for generating pseudo-random numbers

My today's goal was to further practice POSIX shell scripting. So, I decided to write the following POSIX shell script for generating pseudo-random numbers. Any and all reviews would be appreciated. ...
7
votes
2answers
4k views

A random hex generator

This is a program that generates a random hex value. ...
1
vote
0answers
627 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 ...
3
votes
0answers
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 ...
1
vote
1answer
68 views

Pseudorandom telephone generator

Was tinkering around in Python after a long hiatus, and decided to do a very simple fake telephone generator. Anything I can do to improve it? ...
6
votes
2answers
1k views

Print a random anagram of a given string

I am given a task to create a function that prints a random anagram of a given string: ...
1
vote
1answer
353 views

Dice roller in Ruby (mainly for D&D)

I have been working with Ruby for about a week or two now, and I wanted to create a dice-rolling application that intakes any string (e.g. 1d4 + 1 or 3d20 + 4) and outputs the correct dice rolling. <...
4
votes
2answers
622 views

Cryptographic range based random number generator class 2.0

I've corrected the bug in the first version and fixed up the error messages. As for using floating arithmetic, since i'm not using more than 10 digits of the generated double, which, to my ...
3
votes
4answers
2k views

Testing random number generator function

I'm implementing some of lodash JavaScript library functions like (min, max, sum, ceil, floor, random) and unit testing them for practice, however, testing the random function was tricky. The random ...
3
votes
1answer
1k views

Function that loads a random image using an array of paths to images

I have created a program that generates a random image from a folder of all the world's flags. First, it generates an image as it loads, then it can keep randomizing the shown image if the user clicks ...
3
votes
2answers
381 views

Implementing a 64 bit PRNG library in C backed by xoroshiro128+

Introduction and Credits The inbuilt rand() function in C only offers a very limited range of possible outcomes, being limited to only 31 bits. I wanted something ...
7
votes
2answers
442 views

Cryptographic range based random number generator class

Recently had reason to design a range based random number generator that uses the RNGCryptoServiceProvider provided by the .net api. The basic algorithm generates a random unsigned 64 bit integer ...
9
votes
2answers
374 views

Get a random event out of a set of mutually exclusive events

Task: Get a random event from a set of collectively exhaustive and mutually exclusive events, with this set being represented by a list of tuples ...
4
votes
2answers
817 views

Keno lottery game

This code implements the basics of the keno lottery game which are: There are a total of 60 numbers from 1 to 60 to be picked by the player The player can pick 5 to 10 numbers in a game round The ...
15
votes
7answers
9k views

Pick a random big word from a list of words using Python

I am trying to randomly pick a large word (7 letters or more in length) from a large text file of words. I know that there has to be a better and more efficient way to do this. ...
3
votes
2answers
108 views

Getting a random number between a min and a max

I have a function that gets a random number between a min and max. I call the function on a variable as such: let randomPage = getRandomIntInclusive(1, 5); That ...
-1
votes
3answers
84 views

Populate array with random numbers efficiently

I have an initial Excel workbook with about 100 000 rows. I put those rows into array and then use that array to create Client ...
0
votes
2answers
77 views

Generate list of shape in Lisp

I quickly created this function in Lisp that resembles numpy.random.randint(low, high=None, size=None, dtype='I') The goal is simply to have a function that ...
7
votes
2answers
542 views

The performance of the simulation for an ant's random walk on a 5x5 grid

I have written a simulation in order to solve the 280th problem in Project Euler, and the simulation basically repeat the given experiment 5m times, and for each experiment, writes the ExpNo - #...
7
votes
4answers
4k views

Randomly generate a Hex Colour code and its contrasting colour using Python

I am attempting to generate a new colour and its contrasting colour with this python script. I plan to try to make a web app that is different every time it is loaded (i.e. background and text colour)...
6
votes
1answer
166 views

Simple fruit machine game for the Sinclair ZX80 (old ROM)

I've developed a quick Sinclair ZX80 game using z88dk. I used the beautiful C programming language along with a small amount of Z80 assembly. Notes: I'm using integer maths, which is faster and more ...
3
votes
3answers
775 views

Simple Random Password Generator in Python

I've made a password generator that works fine. It takes alphabetic, numeric, and punctuation characters and randomly generates a 8-16 character password. ...
5
votes
2answers
2k views

URL-safe random string generator in C#

...
2
votes
1answer
65 views

Generating user ids on a random forum website

Will this code be random enough to generate user ids for a website where people can create posts? Would there be a better method other than running this function and validating it doesn't exist in the ...
1
vote
0answers
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 ...
1
vote
1answer
503 views

A 3D Random walk simulation

I was referring to the book Computational Physics by Nicholas J. Giordano and was studying the simple Random Walk model. (Pg. 169 - 173) I consider a 3D Random Walk where the probability of moving in ...
2
votes
2answers
681 views

1-50 lottery game

I am a beginner Python "developer" and I was messing with Python while I was offline on vacation, so I made this lottery game. Please leave your opinions on what I should do to improve it. ...
5
votes
2answers
494 views

64-bit Mersenne Twister random-number generator; follow-up #1

This question is a direct follow-up of: Have a look at this Mersenne Twister random-number generator function Thanks to Code Review and Stack Overflow, I now realize, that: ...
2
votes
1answer
1k views

Mersenne Twister random-number generator function

Have a look at this Mersenne Twister random-number generator function that I've written based on what I found on SO. As I am a beginner and don't understand half of the stuff below, I would very much ...
1
vote
1answer
683 views

Java method to load random paragraph from text file

Looking for some critique for this code. but ultimately I would like to be directed to resources/books that address my code writing weaknesses, in terms of style structure an convention : The task is ...
6
votes
1answer
113 views

Xorgens4096 PRNG with global seeder in C#

This is a basic implementation of the non-cryptographic Xorgens4096 pseudo random number generator with a global, thread safe seeder. The goal is to provide a high quality generator that can be ...
3
votes
1answer
135 views

Simulated race among three robots making random steps

At a job interview, I was asked to code the following algorithm: Given are three robots which advance across a 1km lane at a different pace respectively. Each pace made by a robot is of a random ...
0
votes
2answers
400 views

Function to generate radom alphanumeric cookies

I wrote this python function to generate random values to use as id for the cookies I have on my project. These are some examples of what the return is: ...
5
votes
1answer
76 views

Buffered RNG-wrapper using openmp in c++

I wrote a class around a UniformRandomBitGenerator, which in turn also satisfies the concept of a UniformRandomBitGenerator. It ...
3
votes
4answers
932 views

Bootstrap procedure

I wrote this VBA code as a bootstrap procedure (unfortunately, R functions don't allow to extract every resampled series, so I had to do it with Excel and rnd): ...
3
votes
1answer
156 views

Passphrase generator script

Below script is used to generate passphrases for gpg (or anything really). Do you see any blatant security mistakes in it? I wrote it by myself, because I couldn't find any passphrase generator that ...
4
votes
2answers
2k views

Simulates flipping a coin repeatedly and continues until however many consecutive heads are tossed

This program simulates flipping a coin repeatedly and continues until however many consecutive heads are tossed. I'm wondering if there are any issues when initializing a variable in a ...
4
votes
2answers
948 views

Generating stock prices using geometric brownian motion

I am writing a c++ class of "A simple least squares approach" by Longstaff and Schwartz. I have only finished writing a function for creating the stock price paths using geometric brownian motion. I ...
3
votes
2answers
796 views

Counting consecutive streaks in random numbers

I heard that when you toss a die often enough, you could get the value "one" a million times in a row. I am a beginner in Python 3 and I tried to write a little program that generates 1 or 2 randomly ...
1
vote
1answer
393 views

Random winner selector

I am looking to improve and simplify the way I code. What is the best way to represent this: ...
5
votes
1answer
101 views

Make a PPM chain showing a maze generated and solved

Beware: if you run this program with default configuration, it will produce from ~250 to ~1000 plain PPM images in the directory it's being run in, which all summed up will weigh ~4MB. These PPMs can ...
4
votes
2answers
571 views

Discrete random number generator in Python

Description: I am given a list of possible values, each of which have an associated probability of occurrence. How could I improve the algorithm that randomly generates a value based on the given ...
3
votes
2answers
98 views

Randomises capitalisation of letters like bird spongebob

A friend and I have an inside joke; well, not exactly inside if it is based off an existing meme. We would send messages in the 'retarded' form, as the meme 'Retarded Spongebob' does in the example "i ...
4
votes
1answer
63 views

Matching a randomly made colour using sliders

Below is a code which creates a random colour and shows it to the user in a 64 x 64 square. The user must then use the 3 sliders (R, G, B) to match the colour as closely as possible ...
4
votes
1answer
737 views

Java game that generates and compares random numbers, looking for matches

I have written some Java code for a school assignment. It is a game, and it works as follows: The game makes 4 random numbers, all different, as the users ticket. It then generates 4 other random ...
2
votes
0answers
587 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? ...
10
votes
2answers
186 views

Discrete selector

Background I tried to make the underlying container resizable if the corresponding weights are provided. But then, I faced a problem: C++ doesn't have standard interface for ...
4
votes
1answer
141 views

Comparing three C++ data structures for discrete sampling with probability distributions

Introduction A probability distribution data structures receives pairs \$\langle e_i, w_i \rangle_{i = 1}^n\$, (\$e_i\$ is an element and \$w_i\$ is its respective positive weight) and provides a ...
4
votes
2answers
150 views

Random C++ STL-only password generator for education

This is some code I wrote five years ago and I'm now using it partially as instructional material. I think there are some things that are 'off' about it, namely the top of the main function being the ...