Questions tagged [random]

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

Filter by
Sorted by
Tagged with
4
votes
3answers
222 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 ...
5
votes
2answers
599 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,...
3
votes
1answer
93 views

Reservoir Sampling of an enumerable collection of unknown size

I have an enumerable source for which I do not know how big it is. I want to select a random element from it, without having to hold the whole collection in memory and with uniform distribution. I ...
38
votes
6answers
19k 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 ...
4
votes
1answer
57 views

Finding number of possible arrangements of books on a shelf with a Monte-Carlo approach

The Problem I am trying to determine numerically how many possible ways a number of books can be arranged on a shelf. Specifically, there are x3 categories "physics", "sci-fi", and ...
7
votes
2answers
354 views

Convenience function wrapping C++17's std::sample for distance=1 case

C++ has the function std::sample which randomly samples from a range and places the results via an output iterator. My goal is to create a utility that directly returns a single value in the event ...
2
votes
1answer
32 views

convert GCCRandom(Mersenne Twister by Takuji Nishimura and Makoto Matsumoto) to stl random

I am trying to translate the book Game Coding Complete by Mike McShaffry 4E to modern C++17 standard and faced with the code of Mersenne Twister by Takuji Nishimura and Makoto Matsumoto. Is it right ...
1
vote
1answer
196 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 ...
4
votes
2answers
1k views

Find the largest area polygon built from a given list of vertices

This is code that gets a list of polygon vertices, non-ordered, and finds the order in which they should be arranged in order to create the polygon with the largest area. There are two key elements ...
7
votes
1answer
189 views

Metropolis Monte Carlo Sampler in Rust

the following is an implementation of the standard Metropolis Hastings Monte Carlo sampler. You can read more about it here. At the end I am going to give you a link to the Rust playground, so you ...
1
vote
1answer
60 views

find leading zeros: performance

I am trying to find a N number of leading zeros from the output of the sha1 hash function. I would like N to go up to 10 or 9. Currently I can get to 7 in about 7 minutes (even though is not always ...
4
votes
3answers
247 views

This code is a non-static C# class for rolling a number of dice

Hello Everyone! Fellow human beings, today I present to you my dice rolling script! Behold, in my amateurish attempt at some raw C# code. Perhaps this will remain here regardless of the dozens of ...
3
votes
2answers
73 views

Catch The Rabbit Game: How to Create Non-Repeating Randomization? (JavaScript, CSS, HTML)

I've designed this game, it's my first project. It's a spin-off from "The Pig Game" in a JavaScript course. I tweaked the HTML and CSS templates of the Pig Game for the UI, but I did the ...
2
votes
1answer
57 views

Pseudo-random number generator & password generator

I've started learning Rust and decided to implement something on my own from scratch. I've implemented a PRNG and I use it to generate random passwords. Project tree: ...
4
votes
1answer
90 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
2answers
61 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 ...
8
votes
3answers
13k views

Random walk in Python + turtle

I decided to implement a random walk. The rules The rules are easy, an object is moved in the direction dictated by random or pseudo-random numbers. If you want to read more about it, see the ...
0
votes
0answers
35 views

A Tester of Paragraph Merger for Removing Overlapped Duplicated Lines in C#

This is a follow-up question for A Paragraph Merger with Removing Overlapped Duplicated Lines in C#. I am trying to implement a tester for testing the implemented paragraph merger for removing ...
5
votes
1answer
60 views

Two player random number guessing game

I've created a two-player number guessing game in Haskell. My main objective was to practice dealing with "state" in a purely functional language (such as player scores, whose turn it is, ...
6
votes
3answers
543 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 ...
7
votes
2answers
107 views

Method to randomise a string's case

I'm an amateur at programming and have created the following method with which I pass a lowercase string with the idea it is then returned either in it's original ...
1
vote
1answer
51 views

generating stochastic coloured noise for many oscillators

I have a system of n oscillators which oscillate with time. To each of these oscillators I am adding a fluctuating coloured noise term with a different seed for each oscillator. Here is my code for ...
9
votes
3answers
801 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 ...
2
votes
1answer
41 views

Generating random permutation with forced change of order (Secret Santa)

I wrote this function to generate random permutation of input vector, while making sure every element has switched place (for a Secret Santa like purpose). ...
3
votes
2answers
335 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. ...
0
votes
1answer
70 views

Random Cave Generator Design Feedback

I am looking for feedback on my code's overall structure and design. I made a few concessions in reusability for the sake of not overcomplicating things (static/const public variables in the Game1 ...
7
votes
2answers
413 views

Using c++11 random header to generate random numbers

I'm new to programming. I have a question regarding the usage of c++11 random header to generate random numbers. I tried to learn it, but was unsuccessful. Recently, I've tried the following approach ...
33
votes
10answers
86k views

Random string generation

I'm using this C# function to generate random coupons for a system. How can I improve it? ...
4
votes
1answer
280 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 ...
5
votes
1answer
136 views

Using Euler-Maruyama method to solve Ornstein-Uhlenbeck equation (SDE)

I am trying to implement the Euler–Maruyama method and use it to solve the Ornstein–Uhlenbeck process. I am basing my code on the wikipedia page where a python implementation is shown. More generally ...
4
votes
1answer
181 views

Displaying Media with HTML and JavaScript

I have a personal website that I use to share videos and images with friends. Below is a media generator using JavaScript and HTML. Its main purpose is to display one image at a time at the click of a ...
3
votes
2answers
97 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
votes
1answer
74 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-...
2
votes
2answers
244 views

Random game code id generator in typescript

Below is a simple typescript class used to generate a room code for an online lobby-based game (for example, https://jackbox.tv/ uses 4 digit codes to join rooms) The goal of the class is to quickly ...
3
votes
0answers
74 views

Async generation of large buffers of random numbers on the GPU

I would like to obtain some feedback on a simple code I wrote to implement an easy and hopefully fast way to generate a large number of floats with CURAND and use them one at a time. This is achieved ...
5
votes
2answers
297 views

ASCII Random Walk Algorithm

I would like some advice on improving/optimizing a small program I wrote. What it does is run a random walk on a torus manifold with 8 colors that loop around. ...
4
votes
1answer
115 views

Randomizing all class variables in constructor c++

I'm playing around with making random items and decided to implement the following structure. ...
27
votes
2answers
4k 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 ...
48
votes
4answers
27k 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 ...
3
votes
2answers
342 views

Random alphanumeric string generator function (C, Windows, bcrypt.h)

The function uses the Windows "Cryptography API: Next Generation" (bcrypt.h)'s BCryptGenRandom function to generate ...
3
votes
2answers
63 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: ...
6
votes
2answers
99 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 ...
4
votes
1answer
237 views

Rock, Paper, Scissor - Game

This is my first ever created game. I been slowly but continuously learning PHP for the past 2 months and just last night I thought that I might be able to create a simple and very basic game. Due to ...
3
votes
1answer
82 views

Simple Password Generator Feedback

This is my first major project in F#, looking for any critique on how I can make it more standard or more concise. Some things I feel like I could have done better are the command flag parsing and the ...
4
votes
2answers
130 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 ? ...
1
vote
0answers
27 views

Randomly generating invoice IDs

As more fully detailed in my question here, I'm in the process of starting a small, local business and wanted to avoid showing sequential invoice IDs to clients, and instead generate completely random ...
7
votes
2answers
5k views

Generate 6 random numbers for lottery in PHP

This program generates 6 random numbers between 0 and 45 and the numbers cannot be repeated. Can this code be improved? ...
7
votes
2answers
10k views

Roulette game in C++

I'm kind of new to C++ and was just wondering if anyone could give me tips on how I could make my code more efficient (I added some comments to the code to help you understand it better). Is it a ...
1
vote
2answers
123 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
2 3 4 5
15