All Questions

Tagged with
Filter by
Sorted by
Tagged with
9 votes
2 answers
643 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
105 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 ...
1 vote
2 answers
59 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 ...
  • 111
5 votes
1 answer
107 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
336 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
264 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
54 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. ...
  • 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 (...
0 votes
3 answers
101 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 ...
  • 191
2 votes
2 answers
62 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
83 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 ...
  • 13
8 votes
5 answers
3k 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 ...
  • 83
5 votes
4 answers
2k 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 ...
  • 51
-1 votes
1 answer
63 views

Quantum Random Generator outputs pieces of PI [closed]

This is a curiosity as a follow up from Purely Random Numbers Generator ...
  • 23
0 votes
2 answers
108 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 ...
  • 23
8 votes
3 answers
837 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
99 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: ...
  • 195
5 votes
4 answers
4k 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
242 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 ...
  • 27.3k
4 votes
1 answer
130 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 ...
2 votes
0 answers
43 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/...
1 vote
0 answers
33 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 ...
  • 111
5 votes
1 answer
429 views

Monte-carlo simulation code - simple exercise

I created a quick monte-carlo simulation which seems to do what I want (simple version below). The code basically simulates a Poisson distribution, say this results in a simulation of ...
  • 53
2 votes
1 answer
58 views

Python Library for Random Collections

I created a small library Python library to randomly create primitive types and collections. The primitive types are int, float, and string. The collections are tuples of 2, tuples of 3, a list, a 2d ...
2 votes
0 answers
208 views

Python Markov Chain based pseudoword generator

This is a Python 3 module that generates random pronounceable word-like strings based on Markov Chains. It has many modes, each mode conforms to the structures of dictionary words to a degree, the two ...
1 vote
1 answer
120 views

Python 3 weighted random choice function memoized version

I have written a function that randomly picks one element from a set with different probabilities for each element, anyway it takes a dictionary as argument, the keys of the dictionary are the choices ...
-1 votes
4 answers
136 views

Python weighted choosing that works with very large numbers

I have written a function to choose randomly with weights from very large data sets in which the weight of elements can be several thousands. The input of the function is a flat ...
1 vote
2 answers
3k views

Generate random string to match a specific pattern

...
2 votes
2 answers
210 views

Markov text generator program in Python

This is my first non-trivial program in my Python. I am coming from a Java background and I might have messed up or ignored some conventions. I would like to hear feedback on my code. ...
6 votes
1 answer
383 views

Python code for eliminating options for random intergers as they get picked

My goal is to write code that picks several random numbers from a range without repeating any previously chosen numbers. I figured out a functional solution for my problem but it seems very bulky and ...
1 vote
1 answer
271 views

A simple noise visualizer made using Pygame GUI

I was trying to make a simple noise visualizer using the noise, pygame and pygame_gui ...
4 votes
3 answers
1k views

Python random word generator that generates a wordlike pronounceable string

This is a random word generator I wrote in Python 3 today, I don't know how many Python implemetations of this exist, but this is my first try and it is completely working. It returns a random word ...
4 votes
1 answer
127 views

Library for generating passwords

I am going to make this code below into the second release of my library, but I want to make sure I haven't missed anything. If there are improvements that can be made, I'd like to implement them. ...
2 votes
2 answers
153 views

Random walk generator - looking for optimizations (Python)

I just started learning Python and this is the first code I wrote. It's a Random Walk generator. I think I got it to work pretty well but I'm also sure there are more effective and less clunky ways to ...
  • 23
6 votes
3 answers
616 views

Generate random string to match the goal string with minimum iteration and control statements

The following is my python code to find the number of iterations needed to generate random string iteratively to match the input string. Here I have repeated a similar kind of for loop in both the ...
  • 71
9 votes
3 answers
851 views

Applying random luck scores to instances of people

I'm trying to do a simulation on the role of luck in human achievement. Here is what I intend to do with my code: Create 20000 instances of people with randomly generated scores for skill, experience ...
  • 201
3 votes
2 answers
381 views

Generating binary sequences without repetition

I am trying to generate sequences containing only 0's and 1's. I have written the following code, and it works. ...
  • 141
3 votes
1 answer
684 views

Math Random Addition

I am learning python from CS106. Please review my code for Khan Sole Academy, I think my code not efficient. Please add critique and advice for beginner like me. About Code Generate 2 random numbers ...
1 vote
1 answer
507 views

Coin Flip Streaks script

I am attempting to complete the coin flip streaks problem from automate the boring stuff with python. My code works fine but my only concern is the phrasing of the task. Does the question want us to ...
  • 19
3 votes
2 answers
269 views

Creating some Loaded Dice to make our board game fairer

Some friends and I were playing a board game and decided that the random dice rolls just weren't fair! So we came up with a scheme for making the rolls slightly more evenly distributed, and I ...
  • 2,315
2 votes
1 answer
136 views

Procedural generation of a general matrix representing a tile map

The problem is to design an structure which generates "uniformly" the next one in an initially zero matrix. Taking an arbitrary index i in the range [0,m-...
6 votes
2 answers
113 views

My Guessing Game

This is a project that I remade to help me understand function definitions better. It may not be great but I am proud of it. I would love to have you review this project and tell me what I could ...
  • 369
3 votes
2 answers
65 views

speeding up matrix corruption

I need to randomly erase 33% of the non-zero elements in each line of a matrix. Side note: The end goal is to train a denoising autoencoder to remove this noise. My solution: ...
  • 255
4 votes
2 answers
182 views

Mini guessing-game

I am a beginner programmer and I would like to improve in coding and develop my skills. That is why I am asking this question, what should I focus on improving in this code ? ...
  • 369
1 vote
2 answers
314 views

Python - Predicting the probability of 6 Heads or Tails in a row from a set sample size

I'm wondering whether there is a way to make this even more efficient or reduce the number of variables. ...
  • 1,204
3 votes
1 answer
170 views

Test the hypothesis that the expected number of edges of a random connected graph is \$ O(n \log n) \$

Motivation The most common model for a random graph is the Erdős–Rényi model. However, it does not guarantee the connectedness of the graph. Instead, let's consider the following algorithm (in python-...
4 votes
2 answers
738 views

Ising model simulation using metropolis algorithm

I am new to this community; I have tried my best to respect the policy of the community. I have written the Monte Carlo metropolis algorithm for the ising model. I want to optimize the code. I have ...
1 vote
1 answer
204 views

Simulating a Rock, Paper, Scissors Game - Flexible

Today I learnt the basics of OOP. I have tried to apply them to this Rock-Paper-Scissors project. However I'm still a beginner, and so I feel my code can be improved. Are there any tips, trick or ...
  • 1,204
4 votes
1 answer
272 views

Simulated annealing for magic square-of-squares puzzle

I'm working on a function that takes in a NumPy array containing only mutually distinct positive square numbers. I want the function to pick an element at random, find if there is a lower positive ...
  • 157
3 votes
1 answer
264 views

Von Neumann random bytes debiasing

I need to create a method to debias biased bytes from the method get_raw_bytes(length) using von Neumann debiasing method. Von ...

1
2 3 4 5