This tag is for questions pertaining to random numbers, whether pseudo random or truly random.
7
votes
3answers
323 views
Better way to create a string of random characters
I'm generating domains with random names but I'm pretty new to Python. I used the map function because it packages the results into a list which I can then join() ...
4
votes
1answer
55 views
Generating random and secure CSRF tokens
I googled around for secure random number generation and random string generation, combining them with some user data.
Is this good or am I totally off-base? I don't know much about cryptography but ...
3
votes
2answers
82 views
Random Name Generator
I've had ideas for something like this in the past but I've finally implemented one and I could definitely use some code review for it. Obviously the quality of the names generated will depend on ...
4
votes
1answer
48 views
Random quote generator
I just began learning programming and I'm learning Objective-C. I'm taking an online course and in that course we were doing a magic crystal ball app. Then I decided to use what I learned and make my ...
9
votes
2answers
341 views
Dice-rolling simulator
I know there is a better way to store data. What is the most concise way to simplify this script?
...
3
votes
0answers
25 views
Is there a simpler or more efficient way to display random “ads” from an XML document?
I have an xml document that contains "ads" and includes information about the department name, image name, link to URL, and alt text. I have a ...
9
votes
2answers
260 views
Card shuffling with Fisher-Yates method
The code below takes a specified number of card decks, and shuffles them according to the Fisher-Yates method. Does this implementation have any bias?
...
6
votes
3answers
444 views
Random number guessing game
I'm working on a random number guessing game. I'm done with the code and it's working, but there is a part that I want to make better. I declared an instance of a ...
5
votes
3answers
321 views
9
votes
1answer
74 views
Produce bitcoin private key from 31 playing cards
I've written some Python code to generate a random hexadecimal string using 31 playing cards drawn without replacement (so no card appears more than once). This is sufficient to provide more than 160 ...
9
votes
2answers
104 views
Can this secure, random generator be improved?
This random generator uses cryptographically secure numbers/chars instead of Math.random(). The Javascript code with jQuery works well but I affect clean code ;) It ...
4
votes
1answer
156 views
19
votes
1answer
322 views
Random clothes generator
UPDATED, original code can be found here.
Also, my main goal is to not only improve the style of my coding, but also to improve the logic in finding random combinations. As of now it seems way too ...
2
votes
1answer
91 views
Dice notation roller in JavaScript
I have the following function, intended to take standard dice notation (XdY+Z) and return a (sort of) random number based on the input. Are there any bugs/bad ideas/optimizable sections I am missing?
...
14
votes
5answers
2k views
1
vote
1answer
84 views
Reservoir sampling
Reservoir sampling implementation. Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items from a list S containing n items, where n is either a very large or ...
4
votes
3answers
96 views
Weighted probabilistic sampling
Problem description.
Returns strings with probability determined by the frequency
of each of the strings.
eg: if "foo" has weight of 50% and "bar" has weight of another 50% then both foo and
bar ...
5
votes
3answers
96 views
Could random unique selection using while cause an infinite loop?
I recently came across code that looked something like this (generates 4 random numbers in an array, this is not the actual code, I just wrote this up now, so it's untested):
...
18
votes
6answers
4k views
Guessing a unique 4 random digits number
I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using Random() Each of the 4 digits are different from ...
21
votes
9answers
4k views
Generating Even Random Numbers
I have this class which is used as part of a game. It needs to generate Random Even values, which is done by generating random numbers until the result is even.
Is there a better way to do this?
...
6
votes
6answers
914 views
Random number game
I have created a small 'game' which basically asks the user for the row number and column number and then picks a random number and if that number is above 11, out of 15, the user wins. When the user ...
5
votes
2answers
269 views
Generating random numbers
I'm trying to refactor the following code and could use some suggestions. Basically, three functions generating random numbers in different ways are called:
...
6
votes
2answers
209 views
Generating random HTML color grid
This is a Python script that generates a grid of random HTML colors. It works by reading random data from /dev/urandom and then encoding it as a hexadecimal ...
4
votes
2answers
215 views
Roll a die according to the number of sides that the user enters
I have created a program which rolls a die according to the number of sides that the user enters:
...
2
votes
2answers
205 views
rand number generator with limits in ruby
I have an array of 1000 numbers, randomly generated. 10 of those numbers must be between 0-9 (including 0 and 9), and 10 of those numbers must be between 991 and 1000 (including 991 and 1000). This is ...
4
votes
1answer
176 views
Function to produce unique random numbers
I've been learning Haskell for a few weeks after coming from a C# background. I've written a function to return a number of unique Ints from a specified range:
...
6
votes
4answers
147 views
Valid and safe use of SpinLock in Singleton?
Is this a valid and safe use of .NET's System.Threading.SpinLock?
Why am I doing this?
Random's public methods are not ...
4
votes
1answer
66 views
-3
votes
1answer
150 views
trivia questions with 10 random questions from 24 but without repeating the questions
I have a big problem with my project 4-5, I'm trying to have random 10 questions of 25 and not repeating the same questions but I really don't know how to do it. Do you have any hints for me? this is ...
8
votes
2answers
449 views
Guess a random number between a selected interval
My project for my class is to create a Java-based game where the user must enter a number between 1-20 and a number between 250 and 300. The computer randomly chooses a number between those 2 numbers. ...
12
votes
5answers
545 views
Optimize random number generator
I have a method that generates a 10 digit random number where each digit occurs only once.
eg:
0123456789
3645720918
Is there any way this method could be ...
2
votes
3answers
245 views
Modeling a pair of dice using composition in C++. Am I doing it right?
I've written a program all by myself, but I just want to make sure I did it right and if anybody has any suggestions on improving it in any way.
Define and implement the Die class depicted by the ...
2
votes
1answer
352 views
How to improve efficiency of my roulette game?
Well, I'm kind of new to C++ and was just wondering if anyone could give me tips on how I could make my code more efficient (I added some comments to the code to help you understand it better).
Is it ...
4
votes
4answers
1k views
Random walk on a 2D grid
The program assignment:
A drunkard in a grid of streets randomly picks one of four directions
and stumbles to the next intersection, then again randomly picks one
of four directions, and so ...
1
vote
2answers
81 views
How to make this random number game better?
I'm a newbie trying to teach myself Python. Could somebody tell me if there is a better way to write this? I am also curious as to whether or not there is anything I should not do. This code does ...
0
votes
1answer
170 views
Random string generator [closed]
I have made a simple number generator, and I have a question: is it possible for the generator to eject "red", "blue", "green", " yellow" and "white" instead of the numbers 1-5?
...
1
vote
2answers
2k views
A simple Dice Roll game
This is the code for a simple dice roll. Any opinions for this are welcome and any suggestions to improve it would be appreciated. Is there a more efficient algorithm to generate random numbers in ...
4
votes
3answers
328 views
Random number generation in Dice class
I don't intend on implementing this into an application yet as I'm going to test it first. As such, it doesn't do much beyond rolling. It also overloads some "typical" operators such as ...
6
votes
3answers
1k views
Craps game rules and code
I'm developing a small craps game in C++, and my C++ skills are a bit rusty. I really need someone to review my code to ensure that I have correctly implemented the game according to the rules.
...
4
votes
1answer
158 views
What do you think about this uint64 random generator?
I've looked for a good method to generate an integer inside a range of values. I think using modulo is not a good method because the values are not perfectly mapped in the range. So I mapped the ...
8
votes
3answers
589 views
Improve random password generator
Can you please take a look at my code and improve it (if necessary)?
http://jsfiddle.net/U6R6E/
Javascript (with jQuery)
...
4
votes
3answers
2k views
Random String generator in C
I created this small function just to practice C code. It's a simple random string generator.
...
1
vote
1answer
208 views
1
vote
2answers
238 views
Am I on the right track with this random number array?
Is this the best way of doing this? I wanted to make sure the grammar is correct when the array is output.
1 car, 2 cars.
The output is correct but is there an easier way generally? I just want to ...
2
votes
1answer
655 views
Generating random numbers in multiple threads
I'm trying to learn how to use threads to generate lots of random numbers. In particular, I'd like know:
Is the following code thread safe? (I think the histogram class is the only one that requires ...
0
votes
3answers
46 views
RAND() with a generated link
I have a project from my college. I'm making a site which will display different quotations each time the page is loaded. I use the following code:
...
-1
votes
1answer
967 views
Count the repeating number from randomly generated integer [closed]
My Code
This is a simple code that generate random integers between 1 to 100.
...
2
votes
1answer
129 views
Opinions/Improvements on a run periodically/timer function in Python 2.7
I'm looking for some opinions on this bit of code that I wrote and if there are any ways it can be improved.
The scripts aim is to run the function runme() every 60 seconds with a random interval ...
2
votes
2answers
148 views
Shuffling algorithm suitable?
Just checking that this shuffling algorithm is suitable. Or maybe there could be improvements?
...
8
votes
1answer
279 views
Random Generation From Sequences
With the inclusion of <random> into C++11, we can finally chuck out std::rand and start using generator with much better ...