Questions tagged [random]
This tag is for questions pertaining to random numbers, whether pseudo random or truly random.
799 questions
5
votes
1
answer
63
views
Generating random bytes
I implemented a simple function that generated random bytes Vec<u8> with given n size. Then I wondered how can I optimize ...
5
votes
1
answer
115
views
Cryptographically secure random int in range
I tried to make a cryptographically secure random int in range generator for javascript, practically the javascript equivalent of php's random_int(min,max):
...
14
votes
1
answer
1k
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
3
answers
150
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 ...
6
votes
1
answer
481
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 ...
2
votes
3
answers
690
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.
...
3
votes
1
answer
69
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 ...
5
votes
2
answers
114
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'...
3
votes
3
answers
208
views
Casino Number Guessing Game
I have created a casino number guessing game in C++:
...
4
votes
1
answer
366
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 ...
4
votes
2
answers
3k
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, <...
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 ...
4
votes
0
answers
177
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.
...
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 ...
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.
...
3
votes
1
answer
155
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?
...
9
votes
2
answers
888
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 ...
0
votes
1
answer
693
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 ...
2
votes
2
answers
86
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 ...
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 ...
2
votes
1
answer
155
views
Rolling my own PRNG in Java
I have this pseudorandom number generator:
...
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 ...
4
votes
1
answer
77
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 ...
2
votes
1
answer
309
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.
...
5
votes
1
answer
377
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 ...
4
votes
2
answers
995
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 ...
2
votes
3
answers
719
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 ...
4
votes
1
answer
69
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.
...
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 (...
2
votes
1
answer
368
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 ...
1
vote
1
answer
480
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 ...
0
votes
3
answers
125
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 ...
2
votes
2
answers
104
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 ...
1
vote
2
answers
96
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 ...
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 ...
5
votes
3
answers
351
views
Cryptographically secure version of the core array_rand() function
I want a cryptographically secure version of array_rand(). Is this it?
...
5
votes
2
answers
839
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 ...
3
votes
1
answer
197
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 ...
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 ...
-1
votes
1
answer
69
views
Quantum Random Generator outputs pieces of PI [closed]
This is a curiosity as a follow up from Purely Random Numbers Generator
...
0
votes
2
answers
133
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 ...
3
votes
0
answers
55
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 ...
-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 ...
8
votes
3
answers
875
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 ...
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:
...
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.
...
2
votes
1
answer
434
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 ...
4
votes
1
answer
289
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 ...
1
vote
1
answer
507
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 ...
2
votes
1
answer
128
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'...