Skip to main content

Questions tagged [random]

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

Filter by
Sorted by
Tagged with
10 votes
1 answer
868 views

Typical password generator in Python

Password generators are extremely popular on CodeReview with beginners to both coding in general and Python in particular, for a number of reasons: They're (seemingly) easy to implement They offer an ...
3 votes
2 answers
117 views

Efficiently generate a random position inside an outer rectangle but outside an inner rectangle

It should be a uniform distribution (ie: every point is equally as likely). I also don't want to use the simple solution of: "in a loop check to see if the current generated point is within the ...
Ryan Peschel's user avatar
6 votes
1 answer
413 views

Generate unique temporary file names in C++20

WARNING: do not use this solution See discussion in the accepted answer's comments. Basically, this solution would reproduce std::tmpnam's and ...
nilo's user avatar
  • 579
2 votes
3 answers
686 views

Step-by-step re-arranging of a string with randomized characters

A sloppy code featuring algorithms to efficiently randomize the characters of a string "Hello C" and then print out in the console the re-arrangement process for every character. ...
Edenia's user avatar
  • 1,568
3 votes
1 answer
62 views

RandomNumber wrapper in Lua

This is a wrapper I wrote for math.random(). I have a larger program that will create a JSON file to 'load' from when I want to resume. However my program heavily ...
dustytrash's user avatar
  • 2,406
5 votes
2 answers
112 views

Seeded PRNG in JavaScript and Python yielding same results

So I need a PRNG in Python and JavaScript that yields the same results, which is the reason I can't use the built-in methods. It doesn't have to be very good or even cryptographically secure, since it'...
Amaterasu's user avatar
  • 205
3 votes
3 answers
189 views

Casino Number Guessing Game

I have created a casino number guessing game in C++: ...
kit.kat.code's user avatar
4 votes
1 answer
359 views

Porting xoroshiro1024** from C to C#, and seeding it

I require a PRNG which: Has repeatable results from a given state. Is both seeded from and has a state containing a sufficiently large amount of data (somewhere in the region of 700 bits or more) to ...
Pikanchion's user avatar
4 votes
2 answers
2k views

Making a dice game as my first Python project!

I just started my programming lessons in school today and I decided to start learning more at home. This is my first day and I know the basics of if conditions, <...
Ekwa's user avatar
  • 41
4 votes
4 answers
1k views

Lottery Analysis (Python Crash Course, exercise 9-15)

I was working on Python Crash Course, exercise 9-15: 'Lottery Analysis'. It took me a very long time to get it to work. The reason it took that long is I wanted to use my existing class from the ...
snapieee's user avatar
2 votes
0 answers
141 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
10 votes
3 answers
2k views

Python command-line program that generates passwords

I took my code from this answer by me, I found it useful, so I developed it further, and here is the result. This script generates cryptographically secure passwords. The characters used by the ...
Ξένη Γήινος's user avatar
10 votes
3 answers
3k views

Python \ random password generation code

I have written a python program for random password generation and as a newbie I would like my code to be reviewed by professionals and if they have any suggestions to improve it. ...
M.alizadeh's user avatar
3 votes
1 answer
153 views

JavaScript seedable Math.random

I made an implementation of xoshiro256** in JavaScript, using BigInts. It's designed to mimic Math.random. Any feedback on the code quality? ...
rfl890's user avatar
  • 101
9 votes
2 answers
872 views

Simulation of hero vs monster

I fairly started coding no more than 2 weeks now; not even for long, and a thread inspired me to make a random back-to-forth game between a Hero and a Monster where it randomly choose a certain number ...
doobiebob's user avatar
0 votes
1 answer
667 views

Random Name Selection from a "Hat" in Python

Background/context: This program randomly selects predefined items ("Names" as strings) according to 2 rules: #Rule 1: Each name/item in the list can only be selected once. #Rule 2: Single ...
Christian R's user avatar
2 votes
2 answers
83 views

Return a random integer with a probability progression

A function random_int_with_probability that returns a random number within a range, where the chance to get a bigger value decreases linearly towards the maxima. In ...
Edenia's user avatar
  • 1,568
1 vote
2 answers
74 views

Create a random list of values with corresponding tokens

I have this code that uses loops and random generators to create a random list of values (operators, strings, integers, floats, and new lines) and a corresponding list of the correct tokens to test a ...
Finn E's user avatar
  • 111
2 votes
1 answer
151 views

Rolling my own PRNG in Java

I have this pseudorandom number generator: ...
coderodde's user avatar
  • 28.9k
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
4 votes
1 answer
76 views

Piece-wise radial uniformly random distribution of points around a reference point

I have been learning Asymptote, which is a vector graphics programming language. In addition to its nice integration with LaTeX and friends, it is capable of generating 3D rendered artworks. For a ...
user avatar
2 votes
1 answer
303 views

Pick two random cards from a standard deck

I wrote this code as a refactor of code I saw on Programiz. I thought about this refactor before going to bed and implemented it successfully in code. ...
dylanm's user avatar
  • 23
5 votes
1 answer
365 views

blackjack dealer hand generator

I wrote a piece of blackjack code - for dealer dealing cards to himself (python). My question is how can I make it more efficient, faster and neater. I ran it for 1.000.000 iterations and it took 14.7 ...
Edward Henry Brenner's user avatar
4 votes
2 answers
975 views

generate lottery numbers to store in a text file

I scripted a program in python to generate lottery numbers for user. There are two playing methods: Lotto6aus49: User can choose any 6 numbers out of 49. Eurojackpot: User can choose 5 numbers out of ...
Stephan Koenig's user avatar
2 votes
3 answers
706 views

Create different groups of students for a number of assignments [closed]

How can I make the code easy? The function which was developed contains the following inputs: students: a list with names of students events: an integer specifying how many group assignments should ...
Festim Besim's user avatar
4 votes
1 answer
68 views

Generating a randomized JSON for testing RabbitMQ

The following code will be used to generate a random json object to be used as a RabbitMQ message body. The code works but I'm sure it can be improved in ways that I am not seeing, as I am a novice. ...
Johnny's user avatar
  • 41
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
2 votes
1 answer
365 views

Simple ID Generator

Task Write a program that can generate and manage collections of IDs. The user should determine how long the IDs have to be and what symbols they are composed of. Design choices made by me The ...
Dexter Thorn's user avatar
  • 2,174
1 vote
1 answer
471 views

Generate random int based on a 32 characters long string seed

I want to generate a random seed based on a string value (which is ~32 characters long). I don't want to use string.GetHashCode() since I may later will need a ...
DoubleVoid's user avatar
0 votes
3 answers
123 views

A more elegant way to uniformly sample from non-negative integers with a fixed sum

Given a positive integer n, I would like to randomly output n non negative integers that sum to ...
Simd's user avatar
  • 191
2 votes
2 answers
102 views

Sampling from k circles with different radii

Description: I would like to sample n_points points from k circles whose radii and centers are given as lists. Note: This is my ...
ThePortakal's user avatar
1 vote
2 answers
95 views

Generating random integers in one of three ranges

I have a function returns a random integer number. This function only accepts these three numbers 1,2 and 3(there's another function in my code which is make sure of this otherwise that function will ...
Ahmed's user avatar
  • 13
8 votes
5 answers
4k views

Simple Python code that makes a random string of letters and numbers

My code basically picks random letters and numbers from three lists and makes a random combination with them. I decided to write this code just for fun, however I feel like the code can be made ...
Jea's user avatar
  • 83
5 votes
3 answers
346 views

Cryptographically secure version of the core array_rand() function

I want a cryptographically secure version of array_rand(). Is this it? ...
hanshenrik's user avatar
5 votes
2 answers
814 views

Truth or dare program in java

I wrote this code in Java as a "Truth or Dare" game where if you type "truth" or "dare", it will pick a random number from the switch and then output the truth question ...
Harpsickle's user avatar
3 votes
1 answer
196 views

Randomly set styles with JavaScript

I have created a function which randomly sets styles using CSS selectors. Right now it returns a random item from an array. The program also works with shorthand properties (such as ...
Gibberish's user avatar
  • 109
5 votes
4 answers
3k views

Coin flip streaks in Python

Below is the wording from the problem in Automate the Boring Stuff book. The bold text leads me to believe that I should be checking for a streak and not multiple streaks within each experiment of 100 ...
a-rizzo's user avatar
  • 51
-1 votes
1 answer
68 views

Quantum Random Generator outputs pieces of PI [closed]

This is a curiosity as a follow up from Purely Random Numbers Generator ...
Pinchi's user avatar
  • 23
0 votes
2 answers
132 views

Purely Random Numbers Generator

I think the best Random Number on the Planet is PI. I wrote a code that generates a list of pseudo-random numbers in Python. Then it treats this list as positions of digits in Pi and then outputs ...
Pinchi's user avatar
  • 23
3 votes
0 answers
53 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
  • 247
-2 votes
1 answer
6k views

Choose a word randomly from input, without storage [closed]

It is a practice assignment (optional). The question is asking to "Write a program RandomWord.java that reads a sequence of words from standard input and prints one of those words uniformly at ...
DGKang's user avatar
  • 105
8 votes
3 answers
870 views

Finding the perfect statline for a roleplaying game using Python

I made a program for fun that tries to roll a perfect statline, i.e a statline with two groups of only 18s, for a role-playing game. I'm still a newbie in python so mainly trying to learn how to make ...
HighestPie's user avatar
0 votes
1 answer
167 views

Python - Efficiently pick random data from an array, generate random UUIDs and save it all in an Excel table

I wrote the following prototype: ...
Munchkin's user avatar
  • 195
5 votes
4 answers
8k views

Get random time between two time inputs

This code takes two times as input and then calculates a random time between the two inputs. ...
DumbMathBoy's user avatar
2 votes
1 answer
429 views

Robotic swarm simulation: aggregation

This program simulates the phenomenon of aggregation of a swarm of robots with no cooperation between each other and each robot following a very simple rule: The velocity of this robot has a random ...
Caridorc's user avatar
  • 27.5k
4 votes
1 answer
285 views

Let's get random, extending Python's base random class

So Python's base random class uses the Mersenne Twister as its base for seeded random number generation. If available, it can use /urandom/, but that is beside the ...
N3buchadnezzar's user avatar
1 vote
1 answer
478 views

C# PRNG class based on xoshiro256**

Background I'm creating a (probably bad) map-generation utility in C# to generate fractal terrain and similar. Nothing I do probably needs special treatment, but I thought it best to start with a good ...
MichaelS's user avatar
  • 176
2 votes
1 answer
106 views

Any issue with this as a password generator?

Was trying to create a password generator like the one Bitwarden has... Curious if anyone sees any issues with this? (wordlist shortened for readability) There perhaps there's a more efficient way I'...
meowsoftly's user avatar
2 votes
0 answers
63 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
1 vote
0 answers
69 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
2 3 4 5
17