Questions tagged [random]

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

Filter by
Sorted by
Tagged with
94
votes
16answers
177k views

Generate random numbers without repetitions

I want to generate a list of N different random numbers: ...
36
votes
6answers
13k views

Random IP Address Generator

randip.py I know there are probably better, easier ways to do this. It was just a bit of a learning exercise for the sake of familiarising myself with Python. It takes a single argument (positional ...
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 ...
35
votes
2answers
2k views

Random clothes generator

For the past four years I've attended a private school which requires its students to wear ties. I've found that it's far easier to figure out what combination of shirt, pants, and tie that go ...
31
votes
10answers
13k views

Generating Even Random Numbers

I have this class which is used as part of a game. It needs to generate Random Even values, which is done by generating random numbers until the result is even. Is there a better way to do this? ...
27
votes
9answers
10k views

Generate a list of 10,000 numbers in random order

I am in the middle of an interview process with a company I am very excited about. The position is for a Junior Developer for C# applications. I have a year of experience at my current position as ...
25
votes
10answers
68k views

Random string generation

I'm using this C# function to generate random coupons for a system. How can I improve it? ...
25
votes
3answers
3k views

Proof that I was wrong about Random Number Generators

I wrote this code to show how wrong I was about Random Number Generators. Context: From Comments to this answer to Regularity in the "Rusty Towel of Mutual understanding" that isn't ...
24
votes
6answers
24k views

Guessing a unique 4 random digits number

I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using Random() Each of the 4 digits are different from ...
24
votes
4answers
5k views

6 out of 49 Lottery

In Germany we have a lottery with the following rules: You have to guess 6 numbers. The numbers shall be less than 50 and greater then 0. A number occurs only one time in a game. So you can not guess ...
23
votes
4answers
4k views

Generating 1000 random numbers

I have got the following C code and I feel it is crazy stupid and there must be a better way to do this, but just can't think of one and have yet to learn algorithms. ...
22
votes
5answers
25k views

Simple random number generator

I have been wanting to learn programming for some time now and decided to really give it a shot today. I have edited and read lots of things in Java to fix small issues but never written from scratch. ...
22
votes
4answers
6k views

C++ Coin flip simulator and data collector

Asks the user for the chance of a coin landing on heads, the number of trials per experiment, and the number of experiments. For example, given 5 trials per experiment and 20 experiments, the program ...
20
votes
1answer
390 views

Alea implementation

The following is an implementation of the Alea random number generation approach by Johannes Baagøe, reworked from the rot.js implementation by dropping all the pesky underscore prefixes in the ...
19
votes
3answers
2k views

Shuffling algorithm for a “guess that tune” game

I'm making a "guess that tune" game in Visual Basic 6 that is supposed to play each song in a random order: ...
16
votes
4answers
8k views

20 Ways to do Random Sampling

Here is a (small project) code for practicing Python, it comprises 20 variety of functions that each works to return \$n\$ random samples from a set of data. The code mostly uses the ...
15
votes
5answers
41k views

Basic Java dice game

...
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. ...
15
votes
3answers
755 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 ...
15
votes
3answers
1k views

Simple password generator

Here is a simple password generator in Java: ...
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 ...
14
votes
4answers
4k views

Random name-picker with array

I created a program that picks a champion for a role on the game League of Legends using arrays and random numbers. Is there a quicker and more efficient way of doing this? There is one form that ...
14
votes
7answers
4k views

Monty Hall Paradox in Java

I was wondering if this code looks neat, and if I should change anything. I was planning to implement Frames (or JFrame) tomorrow on it. Would it be a good idea to ...
14
votes
3answers
2k views

Slot Machine Constructor

This is a fun little program I made of a fruit machine gambler, aka "slot machine". What mistakes am I making? How can I make this better OOP programming, less spaghetti? ...
14
votes
2answers
3k views

Pi by Monte-Carlo

I was inspired by this SO post to investigate a good Java8 way to calculate Pi based on simulation. I used a similar task to learn about parallel programming on both CUDA, and Intel Xeon Phi ...
13
votes
1answer
15k views

OAuth Provider token generation

I'm currently creating an OAuth provider in Java using Jersey. To the best of my knowledge Jersey does not provide a method to create oauth tokens so I'm creating my own. For those unfamiliar with ...
13
votes
1answer
761 views

Quasi-random sequences: how to improve style and tests?

The requirements for this one were (original SO question): Generate a random-ish sequence of items. Sequence should have each item N times. Sequence shouldn't have serial runs longer than a given ...
12
votes
5answers
10k views

Optimize random number generator

I have a method that generates a 10 digit random number where each digit occurs only once. eg: 0123456789 3645720918 Is there any way this method could be ...
12
votes
4answers
371 views

Draw random 1's and 0's

I was wondering if anyone would be so kind as to look at this code I've written for practice. Tell me what am I doing wrong, where can I optimize, anything. What this code does is (in terminal) draw ...
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 ...
12
votes
3answers
27k views

Creating a string of random characters

I'm generating domains with random names. I used the map function because it packages the results into a list which I can then join() into a string but the way I ...
12
votes
3answers
184 views

Weighted Probabilities with Integers for Game

The idea here is to pick a skill at random for the player each round. Four skills will be chosen, they are all random, and the same skill can repeat multiple times. The player has a skill level for ...
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 ...
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
0answers
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 ...
11
votes
7answers
7k views

Generate random binary arrays

I am fairly new to C++ programming and I, so far, love it. I just have been trying to make sure what I am doing is fast, unique, readable, and efficient. Is there anyway I can improve this code, or is ...
11
votes
5answers
5k views

Generating a password to save to a .txt file

Here is my basic password generator which saves your password to a .txt file which you can choose the name of etc. ...
11
votes
7answers
3k views

French animal generator

I'm learning Python. I'm making a random animal generator, from 5 txt files. Each file is a list of words for respectively the specie of the animal, an adjective, an origin, and a bodypart with a ...
11
votes
3answers
3k views

License and Registration, Sir

The following code will generate a number plate and then generate a random speed and see if it's speeding ...
11
votes
5answers
30k views

Simple Dice Roll game

Is there a more efficient algorithm to generate random numbers in C++? (This code is working on Dev-C++, but I'm not sure if it works on a Borland compiler.) ...
11
votes
4answers
9k views

Random string of variable length generator

Below is my code for generating a random string of random length. I am using it in integration tests. Currently I have almost 2000 tests running each time a commit is made to master and a few of those ...
11
votes
7answers
2k views

Too-high / too-low guessing game in Swing

I have created this program and it works fine. It's just that its too wonky and huge so I was wondering if anyone knew how I could shorten the program so I didn't have to put all of these into each ...
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 ...
11
votes
3answers
934 views

Souped-up random walk terrain generator

I started learning Python a couple of weeks ago, and to test my new knowledge of Python, I decided to use Pygame to code a random walk terrain generator. ...
11
votes
4answers
1k views

random_iterator in C++

This is a small utility that permutes a C++ standard container without modifying the container being iterated: random_iterator.hpp ...
11
votes
2answers
21k views

Dice-rolling simulator

I know there is a better way to store data. What is the most concise way to simplify this script? ...
11
votes
4answers
3k views

Turning an array of words into a random license plate

This is an assignment question from school: Write a method called licencePlate that takes an array of objectionable words and returns a random licence plate that ...
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. ...
11
votes
2answers
818 views

Simple dice roll using std::string as dice notation

This will be a function that returns a random number from Dice Notation (more on Wikipedia). I will later use this function to determine whether some skill check is passed or not. Is there any need ...
11
votes
1answer
1k views

Solving for Bananas

This code creates a problem for the user to solve (very simple problem) it will then check if the user has got it right and will say so. ...