Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [random]

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

1
vote
1answer
25 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 ...
4
votes
3answers
53 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: ...
2
votes
0answers
22 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 ...
5
votes
2answers
332 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
60 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, ...
3
votes
1answer
57 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
54 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 ...
2
votes
2answers
68 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. ...
1
vote
0answers
24 views

Moderate return-low risk vs high returns-high risk investments

To quantify Buffet's #1 rule of investing, "Don't lose money", I take the assumption that % returns of an investment follow a Normal distribution. Now a high return high risk investment might follow ...
0
votes
1answer
16 views

Assigning zero to random cells in a pandas.DataFrame

I am trying to assign 0 to random cells in a one dimensional pandas.DataFrame. The below code is the best way I could think of ...
2
votes
1answer
87 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 ...
4
votes
2answers
381 views

Bulls and Cows C++ beginner project

I'm not a beginner programmer as I have experience in Node and Ruby, but I'm a beginner when it comes to C++. And as C++ is quite different from these two, I figured I could use any tips, tricks, ...
3
votes
3answers
79 views

Pseudo-truly random number generator

I am creating what strives to be a truly random number generator. As of right now, the implementation uses a mix of mainly nonsense system data and some pseudo-random numbers to generate numbers that ...
9
votes
6answers
3k views

A dice game called “Greed”

This game is a variation of the Greed dice game. Imagine we have 5 dice. We roll, them, and jot down the results. Then, based on this chart: ...
3
votes
1answer
74 views

Orthogonal sampling

I have been staring at what I have produced for almost 5 hours and I still cannot see how and where to improve my implementation. I am implementing an Orthogonal sampling method according to the ...
1
vote
3answers
303 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. ...
2
votes
2answers
58 views

New password generation

...
3
votes
1answer
78 views

Small fast pseudorandom number generator in C++

I've been away from C++ for some time and I'd like to get back up to speed with modern practices, so I implemented a small random number generator described here. Any advice on this piece of code? <...
5
votes
10answers
6k views

Random alphanumeric password generator with GOTOs

I was inspired after this thread on Stack Overflow to create a random 8 character alphanumeric password generator. Sadly, it is closed, so I cannot provide an answer there. Anyway, here is the code. ...
1
vote
1answer
38 views

Implementing a random distribution satisfying RandomNumberDistribution concept

Improving on this code review, I provide logarithmic_distribution to satisfy the C++ RandomNumberDistribution concept implementing the PDF ...
2
votes
1answer
153 views

Random string generation in Java

Can random string generation be faster in Java? Here is my current code ...
1
vote
0answers
114 views

Simple joke guessing game

Based on the many other number guessing games people tend to post as first questions, https://www.xkcd.com/221/, and a crypto class I'm taking, I've decided to implement a number guessing game using ...
4
votes
1answer
84 views

Generate multi dimensional maze with borders and fixed degree on each node type

IMPORTANT: giving too big combination of node count and edge/neighbor count can overflow your RAM and swap file very quickly, thus I recommend staying below 500 on node count and below 50 on neighbor ...
3
votes
1answer
109 views

Good randomness in Python code for a lottery-like game

I'm trying to build a lottery-like game in Python 3.6 where a function selects a winner from a participant list where every participant has a winning chance weighted by the value of the tickets they ...
1
vote
2answers
303 views

Secure random password generator

I am developing an application that must generate a random password for each new user in the system (initial password). My idea is to use passwords of 16 characters long. Would like to know if the ...
1
vote
2answers
220 views

Matching socks from a bag of socks

I was reading the book Algortihms to Live By and was inspired by it to take a shot at simulating How to pair socks from a pile? (sans the efficiently part at the moment). ...
0
votes
2answers
70 views

Randomly select + place an image within a div

I'm working on a proof of concept idea I want to use in a Brutalist styled web page. This would involve having transparent image being placed randomly behind the content on load, I have this working ...
5
votes
2answers
149 views

Random tone generator using Web Audio API

This is a random frequency audio generator made with the Web Audio API by Mozilla. The end-goal is an audio frequency trainer: the website plays an audio frequency and the user tries to guess which ...
6
votes
0answers
65 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 ...
6
votes
2answers
489 views

Pick a random file from a directory tree

I'm working on a python module to randomly choose a wallpaper for my desktop background among thousands of pictures in my photo library. I though I'd make a general function: ...
1
vote
2answers
74 views

Three functions to select a random character, each of which can be used at most twice

I'm attempting to minimise the "duplicate" functions I have defined which do almost the exact same thing, but I'm unsure of the best way to do it, I thought of passing in the type I'm looking for (e.g....
1
vote
2answers
86 views

Lottery in the command line

I have written a game in which the user has to guess six numbers between 1 and 49. I want that my program gets checked in the following criteria: Does this program meet the requirements of object-...
6
votes
2answers
209 views

Random quote rotator

On my website, I created like this banner that rotates quotes from an array I made. ...
5
votes
3answers
619 views

Function for creating unique strings for urls

I wrote this function in order to create unique url's for my site. Using these urls, visitors could demo site functionality without having to create a login. The function was intended to return a ...
7
votes
3answers
1k views

Generating a unique key

I am coming from a Ruby background and I am learning Python. This is a method I've created to generate a URL safe unique key: ...
37
votes
6answers
9k 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
56 views

Haskell K-means implementation

The following is a Haskell backend to a K-means visualisation: I have omitted the API code (exists in a separate module), the relevant endpoints simply call ...
2
votes
2answers
75 views

Random binary digit generation and file I/O

I've recently made a program which generates a (pseudo) random binary digit (1,0) which is tied to a specific subject to learn for every day of the week. The program generates the digits the first ...
1
vote
1answer
860 views

Choose random card from a deck

still new to java and i am trying to improve my understanding and use of OOP concepts.here i am supposed to print the name of a randomly selected card from a deck of 52 cards. Program: ...
3
votes
1answer
80 views

A Ruby script to generate random “people”

I'm working on developing a small Ruby program to generate random data for a Neo4J database, including people, addresses, phone numbers, etc. I'm a total beginner to Ruby, so I wanted to post my ...
2
votes
1answer
33 views

Generating random N-dimensional arrays

For this code challenge, I want to create a performant function that creates a rectangular N-dimensional array. (min_dim_size, max_dim_size) is the span size of every dimension. So ...
10
votes
3answers
4k views

Generate 10 random 3-letter strings

This is a toy project and I am a beginner in Python. I need to create 10 random 3-letter strings, where characters are a - z. ...
0
votes
1answer
3k 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 ...
1
vote
2answers
94 views

Randomly generate set of size M from array of size N

The following algorithm attempts to randomly generate a set of size M from an array of size N. It is not based on Knuth Fisher Yates shuffle, but could someone verify its correctness? ...
5
votes
1answer
98 views

Generating lists populated with random objects

For the purposes of unit-testing in Python, I've written a very simple function for generating variable-length lists populated with random objects: ...
6
votes
0answers
557 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 ...
4
votes
1answer
68 views

Small tile coloring app

I made a small app that revolves around coloring tiles - I am a newby to Python so I am unsure whether I followed the general guidelines correct (use of functions and classes, format, syntax) You can ...
4
votes
1answer
635 views

'Guess the Number' game in Python 3

I am new to learning code, and would love some feedback on how this little game could be improved and/or tidied up. ...
2
votes
1answer
51 views

Generate 2D array with set amount entries

I want to generate an array where each row and column needs to have a random generated amount (between 2 and total size of dimension -1) of true values. Currently I am running each row then columns ...
1
vote
3answers
446 views

Implementation of a linear congruential generator

Here's a simple LCG that I've made to learn a bit more about pseudo random number generation. Is this implementation correct, and if so, how can I improve it further? The following code is self ...