Questions tagged [random]

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

Filter by
Sorted by
Tagged with
2 votes
1 answer
47 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. ...
  • 23
5 votes
1 answer
52 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
64 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
87 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
36 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
3k 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
85 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 ...
  • 2,060
1 vote
1 answer
115 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
100 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
50 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
73 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
3 votes
2 answers
151 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
319 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
132 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
838 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
62 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
83 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
3 votes
0 answers
37 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 ...
  • 215
-2 votes
1 answer
2k 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 ...
  • 105
8 votes
3 answers
809 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
73 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
2k 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
144 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
94 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 ...
0 votes
0 answers
113 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 ...
  • 166
2 votes
1 answer
71 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'...
2 votes
0 answers
42 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
30 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
235 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
112 views

Generating a random ipaddress in C

I was looking to receive some feedback on the function I wrote to generate a random ip address. The code is pretty messy and just wanted some feedback regarding optimizations, memory leaks and best ...
1 vote
2 answers
51 views

Optimal random integer function

What I have Header file: int randomInt(int start, int end); Implementation file: ...
2 votes
1 answer
869 views

React app that uses hooks and shows a random image every two seconds

React beginner here. I'm practicing state and hooks, and I wanted to create a small app that every two seconds fetches an image URL from a service (that returns random images) and shows the returned ...
  • 145
3 votes
1 answer
87 views

Improving performance of 'Prioritized left shuffle algorithm'

I wrote a prioritized left shuffle algorithm (the code is copied from my open source C# project Fluent Random Picker). That means: You've got some values and each of them has a priority (a number). ...
  • 207
2 votes
1 answer
50 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
91 views

Creating a simple one-dimension Sobol sequence generator

A Sobol sequence, a series of low-discrepancy quasi-random numbers in range [0,1], can be generated by first initializing a vector of direction numbers: ...
's user avatar
2 votes
0 answers
155 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
107 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 ...
7 votes
2 answers
1k views

Assign determisitic Orcish names for debugging

Orcish Large volumes of unlabelled data are hard to visualize when debugging; I find it difficult to keep track of the pointers in memory. I have used this code to assign Orcish names, (it's a name ...
  • 1,015
-1 votes
4 answers
96 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
2k views

Generate random string to match a specific pattern

...
5 votes
3 answers
420 views

Randomized Queue with ArrayList from Princeton's Algorithm Book

In the book they recommend to utilize an Array, but I think that it's easier to use an ArrayList instead, is there any problem with that? Is this code well designed? ...
0 votes
0 answers
38 views

Random sample items for testing

This function (in a React web application) code takes a random sample of items to test in each test function, for end-to-end testing: ...
  • 101
2 votes
2 answers
145 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. ...
3 votes
1 answer
1k views

Randomly place Divs on webpage and make sure they don't overlap

Currently I am working on a project for which I want to have the different links (div elements) placed randomly on my webpage. To accomplish this, I first generate a set of coordinates and later check ...
  • 81
6 votes
1 answer
378 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
49 views

Build a fixed-length vector from a recursive factory function

I need a function of type forall (n :: Nat). RandomGen q => q -> Vec n q. Obviously this is possible to do (correctly, don't just ...
1 vote
1 answer
181 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
956 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
2 answers
2k views

Custom UUID implementation on C++

The code's gonna be pretty simple and YES, I do know, what a proper UUID4 implementation is and what are possible approaches to implement RFC 4122. But somewhere there exists a small piece of software,...

1
2 3 4 5
16