Questions tagged [random]

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

Filter by
Sorted by
Tagged with
-1
votes
2answers
44 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? ...
1
vote
2answers
162 views

Beginnings of a Scattergories program

I wrote this program as a start towards implementing the game Scattergories. I had a problem with the _sleep command so I used ...
-3
votes
0answers
24 views

What is the exact alternative of rand() % vector.size() in c++ to java [on hold]

I am facing difficulties of converting rand() % TDx.size() in c++ to java. I convert this as ...
3
votes
0answers
57 views

Quiz for random boolean expressions

Inspired by the various quiz programs on this site, as well as Simon Tatham's puzzle collection, I thought I'd write a quiz that constructs its questions automatically and randomly. A typical session ...
4
votes
1answer
80 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
0answers
41 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 ...
2
votes
1answer
35 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
3answers
1k views

Random Message Generator using Arrays

...
3
votes
1answer
92 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
42 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
54 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
137 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 ...
4
votes
1answer
86 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
49 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
139 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
93 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
313 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 ...
8
votes
1answer
2k views

Randomly sampling a population and keeping means: tidy up, generalize, document?

This is part from an answer to a Stack Overflow question. The OP needed a way to perform calculations on samples from a population, but was hitting memory errors due to keeping samples in memory. ...
2
votes
1answer
96 views

Filling up a hand with random cards that are not yet drawn - Monte Carlo

I would like to know if there is a more efficient way to speed up below code. This function is meant to fill in a set of poker hand with the remaining cards using Mersenne Twister for a Monte Carlo ...
3
votes
1answer
101 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 ...
5
votes
3answers
134 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? ...
0
votes
1answer
4k views

Generating unique alphanumeric ID's of a fixed length

I am needing to generate unique id's for users. The 'unique' part is the problem for me. The 13 character id's which have a format of the following: 0 + random int with range of 1-9 + random letter ...
3
votes
1answer
42 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
91 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 ...
2
votes
1answer
94 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
56 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
137 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
140 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 ...
1
vote
1answer
39 views

Random String Generation module in Python

The module is for facilitating random string generation. The example I use to explain it is the following: Instead of writing ...
4
votes
3answers
633 views

Display four random entries from an array

This code will take the array shown and display 4 random entries in the format shown (or near enough). Are there any parts of this that can be optimised? I'm not happy about the ...
3
votes
1answer
64 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
38 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
1answer
69 views

Incrementing time in a discrete-event simulation of a supermarket queue

A method has been written that increments time in minutes that simulates how much time it takes to process item in a supermarket queue and if there is an empty queue, skip it and loops around to find ...
6
votes
2answers
1k views

Print a random anagram of a given string

I am given a task to create a function that prints a random anagram of a given string: ...
2
votes
0answers
43 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
vote
3answers
247 views

Randomly pick key from dictionary weighted by the keys value

I was trying to write a function that would get a random card from a dictionary of cards in a players deck weighted by the number of cards of each type you have. I don't know if the solution I came up ...
1
vote
1answer
105 views

Vectorized N-Dimensional Random Walk in Cartesian Coordinates

I have written a random-walk routine that I hope to build upon in the future. Before doing so, I was hoping to get some critique. I believe the implementation is correct. I noticed that many other ...
2
votes
4answers
648 views

Password generator in Python 3.7

I am learning how to code in Python by myself and have never coded before, I just want to know if there is any way I can upgrade my PasswordGenerator. ...
7
votes
3answers
201 views

Fluent API for creating random integer arrays in Java

Now I have this fluent API for creating random integer arrays. I can say that I want an array of particular length, having a particular minimum/maximum values and using a particular (or default) ...
4
votes
3answers
239 views

Uniformly generate a number from 0 to n-1 that isn't on a blacklist

The task: Given an integer n and a list of integers l, write a function that randomly generates a number from 0 to n-1 that isn't in l (uniform). Solution 1: ...
36
votes
4answers
18k 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 ...
5
votes
2answers
380 views

Counting consecutive selections of a given number when sampling integers in a range

This script counts consecutive number strikes of a number that you determine in a number-sequence that you also determine. I would be very pleased if this script can be reviewed in terms of ...
1
vote
2answers
157 views

Python password generator

This is considered as my second python project, I made the password generator where user has to input length of password minimum 5. I made the code that it will guarantee at least one lowers case, ...
36
votes
6answers
12k 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 ...
3
votes
3answers
15k views

Generate 16-digit unique code (like product serial)

I am not sure what to call this type of code (16-digit alphanumeric code). Conditions are like this: Digits (or characters) are limited 16 Numeric, alphabet mixed No duplication allowed (not yet ...
3
votes
1answer
60 views

Token generation system in py3.7

I've created a system to generate tokens that could potentially be used in some sort of program: ...
0
votes
1answer
59 views

Probability suite for an array of elements

I wrote a function that can be used to generate a probability distribution for an array of elements (probGen()), and another that can be used to select an element ...
6
votes
4answers
8k views

Generating a random hex color

Is there any better way of doing this? ...
2
votes
2answers
74 views

Return Set<Integer> with random unique Integer numbers between min and max range

I need set of random unique Integer numbers for my unit test. I implemented this method, however I'm not sure if this is best way to implement this. ...