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
4answers
14k views

Random walk on a 2D grid

The program assignment: A drunkard in a grid of streets randomly picks one of four directions and stumbles to the next intersection, then again randomly picks one of four directions, and so on. ...
36
votes
4answers
19k views

Seed std::mt19937 from std::random_device

Many people seed their Mersenne Twister engines like this: std::mt19937 rng(std::random_device{}()); However, this only provides a single ...
5
votes
2answers
117 views

A Simple Cluster Generator v0.2

[NOTE] This question can be depreciated in favor of version 0.3. This is a code revision of a previous post and works well. Code has been reworked to be far more clear and concise, thanks to ...
8
votes
1answer
2k views

Generate a random numbers class

I have made class to setup a random number bases on <random>. It works fine, but I have doubt in ...
3
votes
1answer
121 views

A Simple Cluster Generator v0.3

[NOTE] This question can be depreciated in favor of version 0.31. 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 ...
6
votes
3answers
2k views

Random number generation in Dice class

I don't intend on implementing this into an application yet as I'm going to test it first. As such, it doesn't do much beyond rolling. It also overloads some "typical" operators such as ...
93
votes
16answers
177k views

Generate random numbers without repetitions

I want to generate a list of N different random numbers: ...
11
votes
3answers
5k views

WinForms dice roller

I am writing a dice roller winforms application using C# 2012 VS. Dice roller is set up for playing Shadowrun tabletop. I feel that there might be too much code going into the GUI, but I am unsure ...
7
votes
3answers
8k views

Random number generation seeding in C++

I wrote a small function to return a random in a given range: ...
5
votes
1answer
120 views

A Simple Cluster Generator v0.31

[NOTE] This question can be depreciated in favor of version 0.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 ...
8
votes
3answers
405 views

Generators and Distributions 2.0

In my original question: Generically encapsulating random generators and distributions into a class template I was given some excellent suggestions from two very informative users. I will give a basic ...
6
votes
1answer
463 views

Shuffling an arbitrary list or sequence

After reading this question I wanted to write a short example of how a list or sequence could be shuffled in .net. The result turned out to not be very short: Program.cs ...
2
votes
1answer
425 views

Generating realistic terrain data

I have some fascination with terrain generators, so I whipped up this generator in Python. The way it works is pretty simple, but I figure that I should give an explanation for those who don't want to ...
0
votes
1answer
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 ...
14
votes
4answers
7k views

Sorting 10,000 unique randomly-generated numbers

I have to write this program in java. Write a program name sorting.java that will use an array to store 10,000 randomly generated numbers (ranging from 1 to 10,000 no repeat number). Here is what ...
5
votes
2answers
8k views

Generating random sequences while keeping sum fixed

The output is a random sequence, and the input is the sum of the sequence. My solution is generating a random number rand_num from (0, sum_seq) at first, then draw another number randomly from (0, ...
15
votes
3answers
754 views

My images have secrets A.K.A. the making of aesthetic passwords

This is my implementation of a prng steganography tool written in Python. You can also find the code on GitHub. Steganography is the art of hiding messages in (images, videos or even audio) I've ...
12
votes
3answers
3k views

Random Number Generator Class

I've written an abstract class in C# for the purpose of random number generation from an array of bytes. The .NET class RNGCryptoServiceProvider can be used to ...
5
votes
3answers
762 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? ...
8
votes
1answer
1k views

Simple random generator

Based on this question, I have made a simple program to print a sequence of random numbers. The program seems to run fine, but I would like to know if my implementation is correct and how I can ...
5
votes
2answers
298 views

Randomizing and mutating algo class - style

I've updated this question to be about code style only, as all of it's answered focused on this aspect. For the codes function, see Randomizing and mutating algo class - functionality ...
5
votes
2answers
218 views

Random tone generator using Web Audio API

This is a random frequency audio generator made with the Web Audio API by Mozilla. The end-goal is an audio frequency trainer: the website plays an audio frequency and the user tries to guess which ...
1
vote
0answers
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 ...
1
vote
1answer
88 views

A Simple Cluster Generator v0.1

[NOTE] This question can be depreciated in favor of version 0.2. The purpose of this code is to produce a universe of points, randomly generated around predetermined centroids, provided as a vector ...
12
votes
2answers
2k views

Random D20 number generator

I'm teaching myself code using Zed Shaw's Learn Python The Hard Way, and I got bored during one of the memorization lessons so I thought I would make a random D20 number generator for when I play RPGS....
12
votes
4answers
3k views

Rubik's cube timer & scrambler

This uses a linked list to store the data. I used a linked list as it's the only type of data structure that I know currently. Using chrono, I can get microseconds ...
11
votes
3answers
6k views

Craps game rules and code

I'm developing a small craps game in C++, and my C++ skills are a bit rusty. I really need someone to review my code to ensure that I have correctly implemented the game according to the rules. ...
8
votes
3answers
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 ...
5
votes
2answers
152 views

Change random list of numbers into all 5's using simple evolution simulation

This is supposed to be an evolutionary algorithmic program, and I'm not sure if it does what it's supposed to do. It is supposed to take a random list of numbers (containing at least one 5), and over ...
5
votes
2answers
380 views

C++ Random Number Generation

I am making a few wrapper classes for the C++ standard library and was wondering if the following code is good practice. ...
4
votes
1answer
361 views

Small pre-C++11 pseudo-random library

Some time ago (pre-C++11) I wrote a small random number generator library as part of a university assignment. The code has been stored on my hard drive for quite some time and today I dug it out and ...
4
votes
1answer
107 views

Generate multi dimensional maze with borders and fixed degree on each node type

IMPORTANT: giving too big combination of node count and edge/neighbor count can overflow your RAM and swap file very quickly, thus I recommend staying below 500 on node count and below 50 on neighbor ...
3
votes
4answers
2k views

JavaScript Random Color Generator

I made a page to generate a random color with JavaScript and set that color to the background of the page. ...
3
votes
3answers
6k views

Generating a random string of characters and symbols

After coding this, I was wondering if there are any ways in which I can improve upon it. It generates a random string of characters and symbols the same length as what is entered by the user. It uses ...
2
votes
1answer
282 views

Multithreaded Monte Carlo pi approximation with own pseudorandom number generator

I made a Monte Carlo pi approximation program, that makes use of multithreading and a pseudorandom number generator I wrote (the one from big_wheel.hpp, which I ...
10
votes
1answer
170 views

Random Number Generator with Loads of Useless(-ish) Features

For fun, and to refresh my memory on Boost's program_options library, I have written a program with the goal of randomly generating numbers with loads of useless(-ish) features. I have termed it ...
10
votes
2answers
2k views

Playing “craps” for the win

No specific question here. I am beginning with Java and here is an exercise. The rules of game: You roll two dice. Each die has six faces, which contain one, two, three, four, five and six spots, ...
10
votes
2answers
2k views

Guess a random number between a selected interval

My project for my class is to create a Java-based game where the user must enter a number between 1-20 and a number between 250 and 300. The computer randomly chooses a number between those 2 numbers. ...
9
votes
5answers
10k views

Generating new random items from a list

...
8
votes
2answers
940 views

Tidy up number counting code

I am hoping someone can help me tidy up my code (for a practical for university). The practical is to use the random number generator to produce 100 integers (all between 1 and 10) and store them in ...
6
votes
1answer
112 views

Randomly selecting an adjective and noun, combining them into a message

This is my first Rust program. I have previously written a lot of Python, and some C. I would like some advice on whether I am doing things idiomatically, and any improvements I could make! I also ...
6
votes
2answers
2k views

Python dice class

I've built a simple dice class utility for rolling dice. It supports weighted rolling, and usage is fairly simple. Here's the code. ...
6
votes
1answer
406 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 ...
6
votes
3answers
223 views

Initial starting player

I'm making a game battle system, where there are 2 players. Every player can have multiple units to control, but only one at a time. Every unit has an int curSpeed ...
5
votes
2answers
642 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 ...
5
votes
2answers
13k views

Java Dice Roller

I've written a basic dice program in Java which takes a number of faces then randomly selects a number within that boundary. Here is the code: ...
5
votes
1answer
193 views

Randomizing and mutating algo class - functionality

See Randomizing and mutating algo class - style I'm looking for a review of the functionality of this code, answers to the above question which also describes the code use focus on style instead. ...
5
votes
3answers
756 views

Small text-based RPG

This is my first text-based game I made. It's very small because I just learned Python and wanted to start small and then code bigger programs. Please comment on this. ...
5
votes
2answers
517 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: ...
4
votes
3answers
5k views

Testing a Random number generator

Firstly, would appreciate some code-review feedback, from a TDD and design perspective. Secondly, what are your thoughts on implementing test case: ...