Questions tagged [random]

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

Filter by
Sorted by
Tagged with
110 votes
16 answers
242k views

Generate random numbers without repetitions

I want to generate a list of N different random numbers: ...
Kao's user avatar
  • 2,434
57 votes
4 answers
35k 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 ...
Baum mit Augen's user avatar
40 votes
6 answers
22k 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 ...
voices's user avatar
  • 767
37 votes
2 answers
3k 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 ...
Charlie's user avatar
  • 786
34 votes
10 answers
17k 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? ...
leonideveloper's user avatar
32 votes
10 answers
88k views

Random string generation

I'm using this C# function to generate random coupons for a system. How can I improve it? ...
Saeed Neamati's user avatar
32 votes
9 answers
13k 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 ...
DHines's user avatar
  • 421
27 votes
3 answers
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 ...
Malachi's user avatar
  • 28.6k
27 votes
2 answers
6k 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 ...
Georgy's user avatar
  • 1,939
26 votes
6 answers
31k 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 ...
Baby's user avatar
  • 362
26 votes
4 answers
7k 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 ...
Dexter Thorn's user avatar
  • 2,174
25 votes
5 answers
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. ...
Dzzs's user avatar
  • 351
25 votes
4 answers
5k 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. ...
user50585's user avatar
  • 251
23 votes
8 answers
7k views

Random password generator in C

This is a simple password generator. What do you think about it? I am learning C for a while at school and at home. This just has a mix of symbols, lowercase, uppercase and numbers, with a ...
Karol's user avatar
  • 341
22 votes
4 answers
7k 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 ...
Daniel's user avatar
  • 323
20 votes
1 answer
545 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 ...
konijn's user avatar
  • 33.2k
19 votes
3 answers
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: ...
PleaseStand's user avatar
18 votes
4 answers
11k 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 ...
Redsbefall's user avatar
  • 1,132
17 votes
5 answers
50k views

Basic Java dice game

...
user3026468's user avatar
17 votes
4 answers
4k views

Python program to scramble MP3 audio

I'm super new to coding. I had a random idea in the car to make this application in order dive head first into learning to code. This is an app to take an MP3 file, "shred it" into pieces (...
Andrew Worley's user avatar
15 votes
4 answers
9k 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 ...
Fernando Martinez's user avatar
15 votes
7 answers
15k 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. ...
Fendec's user avatar
  • 481
15 votes
3 answers
917 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 ...
Ludisposed's user avatar
  • 11.5k
15 votes
3 answers
1k views

Simple password generator

Here is a simple password generator in Java: ...
Gumberto's user avatar
  • 153
14 votes
4 answers
5k 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 ...
freebol96's user avatar
  • 243
14 votes
7 answers
5k 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 ...
mazunki's user avatar
  • 263
14 votes
3 answers
3k 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? ...
user3224271's user avatar
14 votes
2 answers
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 ...
rolfl's user avatar
  • 97.3k
14 votes
1 answer
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 ...
Chris Salij's user avatar
14 votes
1 answer
785 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 ...
TryPyPy's user avatar
  • 852
13 votes
4 answers
466 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 ...
user avatar
12 votes
2 answers
6k views

Laughably tiny random engine

I devised a tiny pseudo-random engine and I wondered if it would be considered decent or even good. It is based on a SHA256 implementation and uses a single 32-bytes state variable. On seeding, the ...
PinkTurtle's user avatar
12 votes
5 answers
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 ...
Sionnach733's user avatar
12 votes
5 answers
32k 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.) ...
Arpit Agrawal's user avatar
12 votes
3 answers
6k 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 ...
Andy Hoffman's user avatar
12 votes
4 answers
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 ...
Swluo's user avatar
  • 153
12 votes
1 answer
28k views

Generating random email addresses [closed]

The code below generates only 10 email domains. To me, this is bruteforce programming. Is there another random integer library? Could I use something like ...
ERJAN's user avatar
  • 887
12 votes
5 answers
122k views

Random String generator in C

I created this small function just to practice C code. It's a simple random string generator. ...
AntonioCS's user avatar
  • 536
12 votes
3 answers
7k 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. ...
NinjaDeveloper's user avatar
12 votes
3 answers
28k 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 ...
Josh Horowitz's user avatar
12 votes
3 answers
206 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 ...
bazola's user avatar
  • 8,569
12 votes
3 answers
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 ...
Noldorin's user avatar
  • 223
12 votes
1 answer
1k views

Poker probabilities finder

This code finds the probabilities of the various scores in Poker. It uses a Monte Carlo approach, in which, two million (\$2 \times 10^{6}\$) hands are simulated and evaluated, not an exhaustive ...
Caridorc's user avatar
  • 27.5k
11 votes
7 answers
10k 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 ...
Tristen Woodruff's user avatar
11 votes
5 answers
8k 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. ...
Finlandia_C's user avatar
11 votes
7 answers
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 ...
dogspeed's user avatar
  • 111
11 votes
3 answers
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 ...
user2635139's user avatar
11 votes
3 answers
2k views

Completed Town Generator

I am a beginner, and I believe I made a simple and efficient program to do it in. I can add more methods for more detail for future updates, but it's a workable bit. ...
BuySomeChips's user avatar
11 votes
4 answers
14k 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 ...
Ebbs's user avatar
  • 213
11 votes
3 answers
12k views

Random number generation seeding in C++

I wrote a small function to return a random in a given range: ...
GenuinePlaceholder's user avatar

1
2 3 4 5
16