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
24 views

Secure random password generator in Java

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
1answer
39 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
39 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 ...
-1
votes
0answers
19 views

cant figure out how to print random lines from text file java [closed]

//write a program to display 20 random jokes, must follow question-answer format,The program must ask the user if they would like to keep going after each joke. And if the user says no the program ...
5
votes
2answers
81 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 ...
5
votes
0answers
42 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
66 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
68 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
78 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
187 views

Random quote rotator

On my website, I created like this banner that rotates quotes from an array I made. ...
5
votes
3answers
264 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 ...
6
votes
2answers
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: ...
35
votes
6answers
7k views

Random IP Address Generator

I know there's 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 one argument (positional parameter): Either ...
4
votes
1answer
38 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
68 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
96 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
62 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
31 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
2k 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
656 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
90 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
95 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
115 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
64 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
126 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
48 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
185 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 ...
1
vote
3answers
75 views

Picking from a list of individuals based on their fitness values

I have this method that takes a list of my individuals (class has public field fitnessValue). I sum all fitnessValue and then ...
2
votes
2answers
66 views

Math Problem generator using switch statement ,Random method and arrays in Java

I m new in java and created a small project in which you have to solve random math problems there is three levels in it Easy, Medium , Hard, if you win or loss in game the message for three level will ...
3
votes
3answers
95 views

Weighted Probability in Go

I was recently tasked a programming assignment with a prospective company, unfortunately I didn't pass the assignment and didn't receive any feedback on what I could have done better. I would ...
8
votes
1answer
955 views

Markov chains to generate text

This is my Python 3 code to generate text using a Markov chain. The chain first randomly selects a word from a text file. Out of all the occurrences of that word in the text file, the program finds ...
1
vote
0answers
63 views

Unity Tilemap RandomBrush with orientation and probabilities and fixes

Unity3D.com recently released a 2-D Tilemap system. It comes with a really basic RandomBrush for painting a random tile from a list of tiles. But the tiles were not being saved between preview and ...
1
vote
0answers
32 views

Bat file that can create a text file of any exact size and it will be compression resistant

I'm making a bat file that can create a text file of any exact size and it will be compression resistant just for fun. It's currently in 2 parts because that's the only way I could figure out how to ...
5
votes
2answers
77 views

An overloaded random number function template using modern C++

I don't mess around a lot with templates (or with GTK), but today I wrote something and would like to know how it can be improved, and hopefully clarify a few things in the process. So, ...
0
votes
0answers
45 views

ShuffleBag (Fisher-Yates + PcgRandom)

Anything that could be done better here? ...
1
vote
0answers
56 views

GLSL Simplex Noise with derivatives

I recently made 2d simplex noise based coherent noise in GLSL. [Here] is the shader toy. I wanted to make an implementation of simplex noise on the gpu in order to get better performance than the CPU ...
3
votes
1answer
93 views

Randomly generate a Hex Colour code and its contrasting colour using JavaScript

I am attempting to generate a new colour and its contrasting colour with this javascript code. I am making a web app that is different every time it is loaded (i.e. background and text colour) I ...
8
votes
3answers
381 views

Generators and Distributions 2.0

In my original question: Generically encapsulating random generators and distributions into a class template I was given some excellent suggestions from two very informative users. I will give a basic ...
8
votes
2answers
810 views

C++ Random Phone Number Generator

I was tinkering around with C++ after about 3 days of learning and decided to make a random phone number generator. This is the code I came up with ...
4
votes
3answers
85 views

Generically encapsulating random generators and distributions into a class template

I previously had a set of classes in one of my older libraries for working with the random number generators and distributions that was written when Visual Studio 2008 - 2010 were commonplace and ...
3
votes
4answers
678 views

JavaScript Random Color Generator

I made a page to generate a random color with JavaScript and set that color to the background of the page. ...
4
votes
1answer
45 views

Generate another random path through a complete graph

What this does is generate a random path of cities to later calculate the length of the newly generated tour of cities, the TSP. I am trying to figure out if there is a more efficient way to write ...
7
votes
2answers
103 views

Simulating surname convergence in a population

I was curious a few weeks ago about how surnames come and go (mostly on the go). I wanted to know how quickly surnames die out, because (in my simplified simulation world) once the last person with a ...
4
votes
2answers
170 views

C++ Random Number Generation

I am making a few wrapper classes for the C++ standard library and was wondering if the following code is good practice. ...
4
votes
0answers
49 views

Node secure randomness implementations

I'm trying to generate secure randomness in Node as a personal challenge. I was wondering if the following implementations are correctly random or they have some flaws. ...
16
votes
4answers
5k views

20 Ways to do Random Sampling

Here is a (small project) code for practicing Python, it comprises 20 variety of functions that each works to return \$n\$ random samples from a set of data. The code mostly uses the ...
5
votes
1answer
475 views

Simple URL shortener

This URL shortener is just for my own use and it runs on my local machine. I created this for fun and I doubt if I would ever use it in production. Is my script any good? shortener.php ...
6
votes
2answers
64 views

Simple atomic pseudo-random number generation

I like to use a single global PRNG in my c programs (similar to Javascript's Math.random) because it simplifies things and the unpredictable nature of a global is ...
5
votes
0answers
128 views

Quasi-Random Number Generators

I would like to communicate a piece of code which I hope will soon be broadly useful for everyone who programs in C++: A set of quasi-random number generators proposed for addition to boost.random. To ...
7
votes
3answers
318 views

Basic dungeon generator in C#

I decided to make my own dungeon generator, after reading a bit about it. This is my first effort. I can only say that it works, but I believe there's room for some improvement, because I believe my ...