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

learn more… | top users | synonyms

5
votes
1answer
56 views

First text game with Python - Higher or Lower

Recently I have been learning Python programming, for about a week. I have covered all basic stuff - loops, strings, input masks - and have challenged myself by making a little game. It isn't much, ...
6
votes
3answers
90 views

Generate random 10% of file to be used in testing with Ruby

I'm new to Ruby, but not to programming. I just need a simple script that, given a text file, will pull out around 10% of the lines at random. Below is what I came up with based upon a Python script ...
4
votes
2answers
71 views

Pseudo-random number generator implementation check

I was searching for a pseudo-random number generator for C# and stumbled upon Tales from the CryptoRandom by Stephen Toub and Shawn Farkas, so I tried to implement a variation of their code. The main ...
4
votes
4answers
112 views

Random 6 to 10 digits number

I am generating a random numerical 6-10 digit password. I need some important reviews of yours. Is it OK or are there some needed modifications? ...
3
votes
1answer
20 views

Implementing `randoms`

Learn You a Haskell presents the randoms function. I implemented it as follows: ...
9
votes
1answer
74 views

Random Coin Toss in Haskell

Learn You a Haskell gives an exercise to implement the following function: ...
2
votes
1answer
36 views

Ensuring client IDs are unique

I'm writing a node.js application that involves handling clients based on their ID without any real way of confirming that the ID a client says it has is its actual ID. That is, it's possible for a ...
8
votes
4answers
481 views

std::vector composition with self populating super-powers

I have written a deliberately pretty simple class that wraps a std::vector to basically make it capable of self-populate itself with random generated numbers, ...
2
votes
1answer
33 views

v2 - Adding a duplicate entry randomly into a list in haskell using random monad

Next version of Adding a duplicate entry randomly into a list in haskell using random monad I wrote this trying to set up a Haskell testcase. The aim is to take a list and add a single duplicate from ...
4
votes
1answer
18 views

Adding a duplicate entry randomly into a list in haskell using random monad

There's a new version of this as v2 - Adding a duplicate entry randomly into a list in haskell using random monad I wrote this trying to set up a Haskell testcase. The aim is to take a list and add ...
2
votes
2answers
44 views

Simple evolutionary string matching

This is based on a very similar question I asked, found here. The intent of this program is to start with a set number of random strings of zeros and ones, and eventually evolve them to find one ...
5
votes
2answers
79 views

Change random list of numbers into all 5's using simple evolution simulation

This is supposed to be an evolutionary algorithmic program, and I'm not sure if it does what it's supposed to do. It is supposed to take a random list of numbers (containing at least one 5), and over ...
7
votes
2answers
518 views

How random is this password-generating algorithm?

This code's sole purpose is to create a very random password, using letters and numbers. I think that it fulfills its purpose, but I wonder, could it be done better? I'm not talking about ...
5
votes
2answers
94 views

Python script for generating random C code

I'm writing a Python script to randomly generate C functions. This is my first time using classes in Python and I'm basically doing my best to pretend I'm using Java. I'm looking for a review of my ...
1
vote
1answer
33 views

Seeding a PRNG - Custom Setter

I have a PRNG-Class called Generator. Now, after creating a new instance of it: var g:Generator = new Generator(); Custom ...
3
votes
2answers
171 views

Generating a random string of characters and symbols

After coding this, I was wondering if there are any ways in which I can improve upon it. It generates a random string of characters and symbols the same length as what is entered by the user. It uses ...
3
votes
1answer
81 views
7
votes
4answers
662 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 ...
2
votes
1answer
76 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
207 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
396 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
108 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
148 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
84 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
618 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
1answer
43 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 ...
10
votes
2answers
641 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
978 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 ...
8
votes
3answers
365 views
9
votes
1answer
92 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
130 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
262 views

Dice game in Python

I was wondering if this script in Python could be shortened? ...
19
votes
1answer
397 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
135 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
3k views
1
vote
1answer
167 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
120 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
136 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): ...
19
votes
6answers
5k 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
10answers
5k 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
1k 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
512 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
271 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
648 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
462 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
274 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
183 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
203 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
511 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. ...