This tag is for questions pertaining to random numbers, whether pseudo random or truly random.
3
votes
1answer
51 views
Sleeping barber problem in Erlang
I'm learning Erlang. It's my first time with a non-imperative programming language.
I've written a code and I want some thoughts about it:
Is my logic easy to understand?
Is my code idiomatic?
Is ...
2
votes
1answer
79 views
C# console roulette game
I made a C# console roulette game. Check it out and give opinions on how to improve or ideas for some other features? It's not finished yet so it has lots of room for improvement. I am very new so ...
3
votes
2answers
44 views
Cryptographically Secure Pin Generator using RNGCryptoServiceProvider
In my system I have a SMS authentication. Users input their user-id and get sent an SMS with a 5 digit pin number they input in a website to log in. The pin has a lifetime of a few minutes.
This pin ...
-1
votes
2answers
52 views
Maths quiz with difficulty levels and a score database
How can I make the saving to the dictionaries more efficient as well as making my overall code more efficient?
...
-2
votes
1answer
139 views
On Finding Coin Jams
The problem can be found here and is essentially asking us to generate J many numbers containing N many digits, where these digits have to be either 0 or 1. The catch is that the these numbers that we ...
6
votes
1answer
40 views
Randomly selecting an adjective and noun, combining them into a message
This is my first Rust program. I have previously written a lot of Python, and some C. I would like some advice on whether I am doing things idiomatically, and any improvements I could make! I also ...
5
votes
2answers
62 views
Determine playing card
I would like a code review on the coding I did for my assignment. The reason I have asked here is because my lecturer has no intention of going through (Don't ask me why, I asked before and he said ...
1
vote
3answers
74 views
3
votes
1answer
56 views
Generate 6 random numbers for lottery in PHP
This program generates 6 random numbers between 0 and 45 and the numbers cannot be reapeated. Can this code be improved?
...
3
votes
6answers
294 views
Creating an array of random numbers with no duplicates
I only need three random numbers within the range of 1-54 (deck of cards) and none of the three numbers can be a duplicate. I cannot use an ArrayList; I must use a ...
1
vote
1answer
29 views
Using semaphore in C
This is my first time using semaphores and I was wondering if I implemented them to the best of their abilities in my code....
...
5
votes
1answer
102 views
Generating XKCD passwords
Obviously, everyone should use a password manager to generate and store long unique random strings of characters for the vast majority of their passwords. However, one still needs to memorize a master ...
0
votes
2answers
66 views
Random Walk simulator seems slow, are there ways to optimize my code?
I'm trying to write a short random walk simulator in which an agent has a 50% chance on each "round" to either move toward x or back to its initial position. If the agent is already at its initial ...
3
votes
2answers
161 views
Heightmap generation using midpoint displacement
I am writing a program to generate a height map following the midpoint displacement algorithm (somewhat similar to diamond-square).
I'm at the point where I have a recursive program that paints the ...
3
votes
2answers
167 views
“Guess my Number” game in Python (2.7.9)
First time posting to Code Review. Just looking to get some advice on how I can write better code.
I found the following exercise for a "Guess my Number" game on DaniWeb, but the linked source code ...
3
votes
1answer
53 views
Portably generate uniformly random floats from mt19937 output
My goal is to generate a sequence of random float from a seeded random generator. The sequence should be the same on any machine / any compiler -- this rules out ...
-2
votes
0answers
25 views
Assigning distinct random numbers to variables [closed]
I'm attempting to generate non repeating random numbers between 1-5, 1-10, 1-20, etc. I'm on to the Fisher-Yates Shuffle but I'm not sure I've implemented it in the best way. My plan is to associate ...
3
votes
1answer
29 views
Python Weighted Object Picker
I've designed a class ObjectPicker that can be given objects and weights. Objects can be picked randomly out of the ...
9
votes
4answers
2k views
Randomly generate spelling mistake in string
My code will generate a spelling mistake inside of a string 50% of the time.
It will retrieve a letter from a random index in the string like, "t" and then duplicate that letter like, "tt" and store ...
3
votes
2answers
90 views
Simple function to generate a list of letters
I would like get some suggestions for improvement of this function, and alert me about any dodgy practices that you find.
I have been trying to learn python for a short time now and I would like to ...
5
votes
2answers
71 views
Randomized Lighting with Python
I use this to automate the lights in my home while I am away at night (simulating presence). The scheduling of when this runs is handled by my home automation software (Indigo Domotics).
I'm open to ...
2
votes
2answers
35 views
Choose a color with probability proportionate to its weight in a group of colors
Input: An array of colors with weights. e.g [['red', 10], ['blue', 20], ['green', 30]]
Output: A random color from the array, based on it's proportion to the other ...
2
votes
2answers
55 views
Random positioning and movement of a rabbit on a table
I was inspired by this:
If you would put a rabbit randomly on a circular table with radius r=
1 meter and it moves 1 meter in a random direction, what is the
chance it won't fall off?
I ...
2
votes
1answer
52 views
Sampling with weighted probabilities
In an exam question I need to output some numbers self.random_nums with a certain probability self.probabilities:
I have ...
3
votes
2answers
64 views
Adding an 'enemy' to a game (with randomized properties)
I'm working on a game using the now abandoned Famo.us Javascript framework.
I have the game in a running prototype and I'm building with Cordova and running it on an iPhone 6 using PhoneGap.
There ...
2
votes
2answers
134 views
Beginning dice game
This is my first dice game and I have spent countless hours working on it, yet it is still very basic. I was wondering if anyone could spare the time to suggest improvements.
...
4
votes
2answers
57 views
Normalized random position generator
I place various divs on screen by adding random x and y positions successively normalized with this function. My question is, how well is it written? Can I improve it? If so, then how?
I am worried ...
5
votes
1answer
58 views
Creating cover traffic by calling random urls - Javascript loop to decrement float
This is a for-loop which runs once for each step with i>1 and maybe for ...
3
votes
1answer
56 views
Generate voxel terrain with Perlin Noise
For my chunk generator for my game, it currently uses a triple nested loop, which seems very inefficient. It also seems like I could cut down a lot of code in the function somehow. Does anyone have ...
6
votes
4answers
982 views
Random string generator
I decided to make a random string generator for fun, and it works for the most part. Since I'm an amateur at programming, I thought I would post the code to get some feedback on it, and hopefully ...
5
votes
3answers
133 views
Simulation for rolling dice in X-Wing
I've recently started playing the X-Wing Miniature game, and there is quite some math behind some of the dice rolls, as they are affected by many abilities and so on. Manually calculating these is ...
5
votes
1answer
98 views
CIS194: Risk!-style “battles”
After reading LYAH and using RWH as a reference, I've been doing the exercises from CIS194, which is often suggested to beginners on irc://freenode.net/#haskell and ...
6
votes
2answers
44 views
Creating a list of new areas for patches of conserved land within a watershed
I'm writing code to create a list of new areas for patches of conserved land within a watershed based on the current size distribution of conserved land patches that are in the watershed now.
I'm ...
7
votes
2answers
74 views
Simple command-line password generator
I'm very new to Haskell, I've read most of learnyouahaskell.com and played around with some simple things, but this is probably the most 'complicated' bit of Haskell I've written so far. I have an ...
8
votes
2answers
88 views
Random jagged int array generator
I've been working on learning about irregular arrays and thought making a generator such as this one would be a good exercise in applying what I have learned.
The following class generates an array ...
1
vote
2answers
75 views
Random uniqueID for each ID SQL
How can I improve this code? I wanted to know if there's a possibility to remove the for loop, and UPDATE a different ...
10
votes
4answers
855 views
Generate set of random numbers and remove lowest
I'm learning some Python with my kids, and we're making a program to generate D & D characters from user input.
One portion of the code is to generate stats, which are a set of six numbers where ...
12
votes
4answers
970 views
Rubik's cube timer & scrambler
This uses a linked list to store the data. I used a linked list as it's the only type of data structure that I know currently. Using chrono, I can get microseconds ...
3
votes
1answer
192 views
Function to generate a UUID
I am trying to prevent CSRF for my login page (linked from here), and for this I am going to use a random token generator to create a UUID for the session.
The function that I have so far is as such:
...
2
votes
2answers
194 views
C program to generate Seed programs from statically defined Befunge code
My program takes static input, and then number crunches for a few hours. I am currently using Macros, but is there a better, more "user friendly" way to do this without losing on performance.
I have ...
5
votes
2answers
255 views
Mapping & Sorting Randomly Generated Numbers
Below is the assignment I was given and the coding is what I have came up with. I would appreciate criticism on how I did and on ways to have gone differently about it.
You want to number your ...
6
votes
1answer
295 views
Simple random generator
Based on this question, I have made a simple program to print a sequence of random numbers. The program seems to run fine, but I would like to know if my implementation is correct and how I can ...
4
votes
1answer
62 views
Coin flips and Dice rolls in a stored procedure
I saw a post in chat a few days ago, of what I thought was an interesting (albeit fairly simple) statistical challenge:
By @skiwi:
If I shoot once with 50% chance of target A and 50% of target B, ...
3
votes
2answers
118 views
14
votes
3answers
692 views
5
votes
2answers
112 views
7
votes
2answers
382 views
Three-number lottery simulator
Please let me know how I can make it better, especially with avoiding repetition without the need to replace the user guesses.
...
14
votes
3answers
2k views
Seed std::mt19937 from std::random_device
To fill you in: Many people seed their Mersenne Twister engines like this:
std::mt19937 rng(std::random_device{}());
However, this only provides a single ...
6
votes
2answers
60 views
Summing random numbers in parallel
I am playing around with parallelization in Java and am trying to see how to squeeze out more performance on my multi-core box. My machine has 6 physical cores, 12 with hyperthreading.
However, with ...
5
votes
2answers
215 views
Random Engine - follow up
I have ported the code from my previous question "Generate a random numbers class" to C++14 and made a few modifications.
How can I improve it further?
...