Questions tagged [random]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
42 views

My first code - looking for feedback on best practices and things I should avoid doing in the future

After just learning a bit of Python I tried coding something myself. I attempted to do a game of Blackjack, which is far from perfect, and still doesn't have some rules a real game has (in my game an ...
6
votes
3answers
297 views

I made a guess the number game in Python

I just started programming a week ago. Online tutorials aren't my thing, so I decided to just start projects and learn what I need for the project. My first project is a guess the number game. The ...
4
votes
2answers
105 views

A dice roller in C

I am learning C and, for learning purposes, I implemented a roll dicer. It uses arc4random(3) for random number generation, as I couldn't find something better. It works both interactively, if no ...
1
vote
0answers
45 views

Generate random letters containing a word

There is a popular game called 4 Pics 1 Word that presents to the user 4 pictures representing a common word. The word has to be typed by selecting some of the 9 random letters appearing below the ...
2
votes
1answer
119 views

Random Number Generator game

...
1
vote
4answers
101 views

Get a random member of a container

It was not obvious how to get a random member of a container. So I wrote a function to retrieve it given a generator. ...
3
votes
1answer
61 views

Generate random ids from specific numbers of auto generated unique ids

I have this class to generate unique ids and random ids from those unique ids. For the unique ids, it's a sequence of numbers between (start number = given number [start_seed]/or random number (0:...
4
votes
2answers
181 views

How to increase the efficiency of DLA algorithm?

The algorithm: Place seed at the center of the canvas. Release a random walker from the edge. Random walker sticks to the neighboring sites of the seed/previous points. Repeat N(particles) times. ...
3
votes
2answers
116 views

Pick a two different random elements from a given closed range

I wrote a function which picks a two different random elements from a closed range of ints and returns them as a tuple. I would like to take a your feedback, if the solution is a "Clever", "Best ...
23
votes
8answers
6k views

Random password generator in C

This is a simple password generator. What do you think about it? I am learning C for a while at school and at home. This just has a mix of symbols, lowercase, uppercase and numbers, with a ...
0
votes
0answers
15 views

Randomizing array elements with specific conditions for repetition

I have written a function for producing a 16 step array (note[16]), intended to generate two numbers (in this example 1 and 2) with the following conditions: Any of the numbers can only be repeated ...
5
votes
4answers
295 views

Program in JAVA to generate random alphanumeric string

This code will generate a pseudorandom alphanumeric string of given length. I would welcome suggestions on how to make it more random. Beyond that, have I made any convention violations, Exception ...
3
votes
3answers
75 views

Random Function Bias Tester

I wanted to create a short little piece of code so that I could see the biases in the random function. ...
8
votes
3answers
750 views

Rolling dice in a method chain

I've been writing code for nearly 40 years now and am still not too old to learn and understand new things. Right now, my focus is a bit of OO with functional programming combined and C# with Linq is ...
4
votes
0answers
71 views

Estimate area of cropped circle with Monte Carlo

I looking around and not finding anything, I developed a simple function for estimating the area of a possibly cropped circle inside a frame. It uses a very basic MC implementation. It is pretty fast ...
1
vote
0answers
136 views

JavaScript random BigInt

Problem: JavaScript does not provide a random BigInt so there is a need to generate a random BigInt within a given range that is evenly distributed. Solution I have tried many algorithms with a ...
4
votes
1answer
103 views

Random password generator that ensures diversity of character types and absence of confusing characters

I wrote the following password generator, to generate a password in which each character group appears at least at once. ...
3
votes
1answer
58 views

Simple winform that randomizes images in a picturebox

I wrote this code for a simple app that gives us random images. The code works, but I feel like I'm doing something wrong. And one thing I would love to know is instead of grabbing from a folder ...
3
votes
0answers
22 views

Optimization of weightedWinner() and random() function

I have written a Lottery contract that picks winner based on the amount they contributed to the pool. I am looking if the code of weightedWinner function can be ...
10
votes
4answers
796 views

Shuffling multiple iterators in order

I have a Python function w/ specified functionality, and two proposed approaches - which do you prefer, and why? (performance, simplicity, clarity, etc) (both use ...
5
votes
2answers
656 views

Writing 1.5 million rows in a file

I am generating SQL statements (of MySQL format) and writing into a file to create 10,000 tables. Each table contains 5 columns with 1.5 million rows of data in each column. I generated these data by ...
3
votes
2answers
119 views

BiasedOptionChooser<T>: a class to do “weighted random choices”

I need to select "random" elements from a collection. Random is quoted because I must assign a weight to each element; elements with higher weights have a greater chance of being selected. To achieve ...
4
votes
2answers
103 views

Data structure that retrieves each item with a specified probability

I wanted a data structure that allowed me to set the chances of randomly returning each of it's elements. For example, suppose I have a Human class. Every Human has an attribute called eyeColor. I ...
0
votes
2answers
73 views

Random string generator that 'guesses' user inputted word [closed]

This takes a user inputted string, then tries to randomly 'guess' it. The problem is that whenever the input's length is 6 digits or more, it takes an incredibly long time to process it. Is there a ...
5
votes
4answers
642 views

Thread-safe, Convenient and Performant Random Number Generator

I need to generate a lot of pseudo-random numbers in my software. I'm trying to create a elegant (syntax-wise) and performant class that would allow me to generate such numbers and perform other ...
6
votes
4answers
3k views

Create two random teams from a list of players

The task is to create two random teams from a list of players. Given an example of players = ["John", "Mike", "Alice", "Bob"] One example random team would be: <...
1
vote
2answers
137 views

Generate random characters from ranges 0–9 and a–Z

I’m trying to generate 5 characters from the ranges 0–9 and a–Z. Is my solution optimal or did I overthink it a little? Would hardcoding a character list be more optimal? ...
4
votes
1answer
105 views

Random password generator (Java)

I wrote this program recently to generate random passwords for myself. It works well but it's been a long time since I wrote any java and am just looking on ways to clean up the code. I'm also not ...
2
votes
1answer
284 views

Java Perlin noise implementation

I've decided to code Perlin noise generator in Java. It works pretty well, I just want to know If I am doing everything right and if it is a valid implementation! PS : The ...
3
votes
1answer
68 views

Random password generator with choice of three strengths

My code works fine but I definitely have unecessary repeat code. I'd like to use functions so I don't have repeat code. I would appreciate any advise on how to make my password generator code more ...
3
votes
1answer
167 views

Random item generation system to be used in a roguelike

New to programming with the goal being to create my own roguelike. I am mostly interested right now in creating my item generation system. I want the code to create a random item that can then be used,...
4
votes
1answer
62 views

C++ wrapper around uniform mt19937 SequenceContainer [closed]

With the following interface in mind EasyRandom<unsigned int> prng(a, b); auto x = prng(); // scalar auto v = prng(10); // vector I wrote the following ...
4
votes
1answer
84 views

PRBHA-10: A hashing algorithm in Python

So I've been working on a simple little hashing algorithm for Python that I like to call PRBHA-10 for short, or Pseudo-Random-Based Hash Algorithm. This is a hash algorithm in Python that is meant to ...
6
votes
1answer
163 views

OOP demonstration in C++17 using a Pokémon

I want to showcase with as minimal code as possible the basic Object-oriented programming (OOP) principles of Polymorphism, Inheritance, and Encapsulation. I know there are many more principles than ...
5
votes
1answer
675 views

PHP program to generate random phone number

I created a PHP program to generate random phone numbers. A valid phone number: must be exactly 11 digits in length, and must start with any of the values mentioned in the ...
2
votes
2answers
60 views

Generating a list (or a string) with random elements

During implementation and testing of different small hobby projects I often reach the point where I need (at least I like it more) some random data beyond the usual foo-bar strings or lists. Random ...
7
votes
2answers
140 views

Simple function that simulates survey results based on sample size and probability

What is this: This is a simple function, part of a basic Monte Carlo simulation. It takes sample size and probability as parameters. It returns the simulation result (positive answers) plus the input ...
3
votes
1answer
126 views

Random String Chooser

I was tasked with creating the class RandomStringChooser that prints the strings in the passed array in a random order, based on the ...
6
votes
2answers
362 views

Generating 10-character passwords, with 3-6 digits and 3-6 uppercase letters, in C++

In response to a question on Information Security on brute-forcing passwords, I wrote code that helped solve the problem: Generate a password list of 10 character passwords containing only a ...
3
votes
1answer
157 views

Generating Biased Random Values (Walker's Alias Method)

Am simply wondering if I made any egregious mistakes while implementing the Alias Method as an IEnumerator<TElement>; would also like to know if there are any ...
3
votes
1answer
58 views

Simple command-line roulette game

I developed a simple command-line roulette game. Your only options are betting on color, but you can bet multiple times in one round ...
6
votes
1answer
163 views

Qt Number Generator v2

Link to the old question. I tried to learn some new things from the answers and here's what I did: Used Qt Designer so that in Config.h, all member variables and ...
5
votes
3answers
164 views

Python coin flipper

I know this is the simplest code that you have probably ever seen but its the first thing I've ever made. Any ideas on how to improve it or add new functions to it? ...
2
votes
1answer
247 views

Speed up fast poisson disk sampling generator in Python

I wrote a generator class which implements Fast Poisson Disk Sampling algorithm in Python. I did some optimizations like, x ** 2 -> x * x, using unpacking ...
1
vote
1answer
215 views

Advanced love calculator that generates a result based on the similarities between the two names

My love calculator gives a result from 0 to 100% based on these factors: If the first letters of the names are the same. If the number of vowels is the same. If the length of the name is the same. If ...
6
votes
2answers
252 views

Quantum random number generator

I'm working on a Quantum Random Number Generator and wanted to get some feedback on the project so far. I'm using PyQuil to generate machine code for the quantum computer, first to create a bell ...
3
votes
2answers
392 views

Number guessing game in C

This is just a little number guessing game. I know it's simple but I am a newbie in C and I think such a little example can be enough for finding simple design flaws that can than be eliminated. If ...
3
votes
1answer
72 views

Generating random number from a binomial distribution

In my application of Monte Carlo simulation, the crucial part is to generate a random number from a binomial distribution with parameters n = size and p = 0.5. Here is my current implementation ...
5
votes
1answer
41 views

High performance wrapper for CSPRNG arc4random(3)

This function is a wrapper for arc4random(3), a cryptographic pseudo-random number generator on macOS and BSDs, but you can also get it by installing ...
2
votes
0answers
60 views

Password Generation Using Cryptographically Strong Random Number Generation

My goal in creating this project was to create a password generator that was simple enough to be useful as well as sophisticated enough in its random-number generator so as to not be contrived. I ...

1
2 3 4 5
14