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

learn more… | top users | synonyms

7
votes
4answers
395 views

Read from a file and pick a random line

I've been learning Java lately and had some great feedback from the previous threads (hangman and guess a number games). I was challenged by a user to try to get this code done, so I'm posting it here ...
1
vote
1answer
39 views

Optimized solution for a rolling dice code puzzle

I was asked to provide the solution of this rolling dice problem in an interview. When I showed him my solution, he said that there is another way to find the solution. I am looking for answer in PHP ...
6
votes
3answers
193 views

Initial starting player

I'm making a game battle system, where there are 2 players. Every player can have multiple units to control, but only one at a time. Every unit has an ...
7
votes
3answers
349 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
62 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
86 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
52 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
345 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
27 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
279 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
481 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
324 views
9
votes
1answer
75 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
164 views

Dice game in Python

I was wondering if this script in Python could be shortened? ...
19
votes
1answer
323 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
94 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
85 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
98 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
97 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
931 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
280 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
214 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
227 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
222 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
184 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
150 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 ...
-3
votes
1answer
151 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
451 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
548 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
250 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
360 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
338 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
600 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
212 views

Random integer generation in given range

Can my rand_int function be improved? ...
1
vote
2answers
239 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
677 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
983 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. ...