Questions tagged [random]

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

Filter by
Sorted by
Tagged with
5
votes
3answers
6k views

Most efficient way to iterate through arrays/can I use .times method in place of while method?

I created a quick program to test the precision of randomness generated by the .rand method. The primary question is whether I can use the ...
2
votes
1answer
1k views

Discrete random variable generator

There is my SSCCE to generate a value of discrete random variable. values is set of value the RV can take and procents is ...
2
votes
2answers
897 views

1024 bit key generation in php

I want to use this function to store 1024 bit keys in my Mysql database. If you call generateKey(128), you'll get a 128 byte string, same as 1024 bit string. I want to know if there is something wrong ...
4
votes
1answer
762 views

Die Roller for command line

I've written a die roller which can be run from the command line. It currently exists as three files, but I'll say later why I'd like to make it four. The files are as follows: die.py: Defines the <...
5
votes
1answer
194 views

Randomizing and mutating algo class - functionality

See Randomizing and mutating algo class - style I'm looking for a review of the functionality of this code, answers to the above question which also describes the code use focus on style instead. ...
5
votes
2answers
304 views

Randomizing and mutating algo class - style

I've updated this question to be about code style only, as all of it's answered focused on this aspect. For the codes function, see Randomizing and mutating algo class - functionality ...
4
votes
3answers
2k views

Extending java.util.Random.nextInt(int) into nextLong(long)

In java.util.Random the Oracle implementation of nextInt(int) is as follows: ...
8
votes
2answers
970 views

Tidy up number counting code

I am hoping someone can help me tidy up my code (for a practical for university). The practical is to use the random number generator to produce 100 integers (all between 1 and 10) and store them in ...
11
votes
4answers
3k views

Turning an array of words into a random license plate

This is an assignment question from school: Write a method called licencePlate that takes an array of objectionable words and returns a random licence plate that ...
10
votes
3answers
1k views

Is this code an efficient implementation of Reservoir Sampling?

I posted this an answer this to a question about drawing a random line from a file too large to put into memory. I hacked the below code together. In essence, this is what Reservoir Sampling does, in ...
10
votes
3answers
12k views

Generating a random alphanumeric string succinctly and efficiently

I want to generate a random alphanumeric string in ruby, as succinctly and efficiently as possible. The following solution works, but is obviously not very efficient. Please review the following ...
6
votes
1answer
5k views

RPG Dice Roller

This is sort of a follow up to my post yesterday. I'm a relative newbie to Python and before I made a d20 dice roller for RPGs. Now I've made a dice roller for any type of dice, and I would love ...
12
votes
2answers
2k views

Random D20 number generator

I'm teaching myself code using Zed Shaw's Learn Python The Hard Way, and I got bored during one of the memorization lessons so I thought I would make a random D20 number generator for when I play RPGS....
10
votes
1answer
160 views

Creating random maze in Go

...
7
votes
4answers
3k views

Randomly Permute Elements in a List

I want to randomly permute a finite list in the most effective and efficient way in C#. My attempt is as follows. ...
0
votes
4answers
3k views

Random “month & day” with JS

Can anyone review this? ...
5
votes
2answers
187 views

Selecting a random image from a subdirectory

I'm looking for code correctness and improvements for the following code. It's my first step into class based programing. What the class does, is simply to read a directory (path is passed as ...
2
votes
1answer
826 views

Objective-C CF Random Name Generator

Based on a python name generator grammar I found here I've decided to write my own in objective-C. The idea is I can load the grammar from a plist file and generate random names from it. I'm looking ...
8
votes
3answers
2k views

Imitate randomness of a dice roll

I have written some code in Java that consists of two classes. I have tried my best and I want you to tell me if I can improve and how good this is. Also, how important is OOP? Java is an object ...
7
votes
1answer
1k views

Listing the first five perfect numbers in MIPS assembly

I've done some programming in the past, but I'm new to MIPS, which I'm trying to learn on my own. This program lists the first five perfect numbers. It uses the Lucas-Lehmer and Miller-Rabin primality ...
2
votes
1answer
2k views

Craps dice game simulator

This craps game simulator is based on someone else's posted Python code that I've redone for practice. I'm interested in improving readability and making it more pythonic. I used ...
1
vote
2answers
219 views

Die-rolling for ordering

I have a little experience with Python and am trying to become more familiar with it. As an exercise, I've tried coding a program where the ordering of a list of players is determined by the roll of a ...
3
votes
3answers
831 views

Simple randomization program

I'm a few months into learning C++ programming and I want to know if I'm moving generally in the right direction or not with the following code. This is the most advanced thing I've created so far, ...
1
vote
2answers
1k views

Haskell: rndFile and [Char] vs IO String error

...
-1
votes
2answers
8k views

Randomize a jQuery object list

Well this was a simplest code competition at my work. I tried a couple things, they accepted but none of them is I wanted. Because both are always giving same result. I tried to randomize like this <...
1
vote
1answer
1k views

randrename — insert random nums in filenames

I have an old mp3 player with a broken screen. Consequently, it's a real pain to turn shuffle mode on and off; however, there are a few albums that I wanted to mix together and have shuffled for when ...
4
votes
7answers
2k views

Reduce repetitive code in Lotto simulator

I'm extremely new to Java, and I had a bit of an attempt at making something that you could call lotto. I've still got a lot more to go on it, but things are becoming tedious, and I am sure there is a ...
4
votes
2answers
2k views

Algorithm to convert random bytes to integers

I'm trying to convert from random bytes to integers within a range. Basically converting as such: ...
3
votes
2answers
3k views

Random string + encrypt/decrypt

Are there any security flaws in what I plan to do? I need to store the following in my DB: a random string to act as a salt for encrypting a password the encrypted password that used the salt in #1 ...
27
votes
10answers
79k views

Random string generation

I'm using this C# function to generate random coupons for a system. How can I improve it? ...
4
votes
2answers
1k views

Program with random number generation

I am having trouble with the random number generator. For week 0 only, I want to set the starting number of roaches in House A (totalRoachesInHouseA) to 97 and the ...
7
votes
1answer
241 views

Random Q&A system

Basically, I made a simple app for my Android, where it picks a random question for you, and picks specific answers. Only 1 of the answers is correct, while other's aren't. Also, after editing the <...
3
votes
1answer
3k views

JavaScript: Weighted Random Generator

I'm attempting to create a function that will give me a "fish" at random, though a bias random depending on the weight value for the "fish". ...
5
votes
2answers
297 views

Social network evolution

I am writing a piece of code which models the evolution of a social network. The idea is that each person is assigned to a node and relationships between people (edges on the network) are given a ...
5
votes
1answer
690 views

Random Topic Generator

I've written a python module that randomly generates a list of ideas that can be used as the premises for furthur research. For instance, it would be useful in situations where a new thesis topic is ...
4
votes
1answer
691 views

Parsing random phrases from a file

This essentially reads a specially-structured file from the scanner and then parses random phrases and prints them: ...
4
votes
1answer
2k views

Password-generation function using custom seed

After reading an article on Skull Security mentioning the potential weakness of php's mt_rand function because of weak auto-seeding (http://ow.ly/4nrne), I decided to see what -- if any -- entropy I ...
13
votes
1answer
15k views

OAuth Provider token generation

I'm currently creating an OAuth provider in Java using Jersey. To the best of my knowledge Jersey does not provide a method to create oauth tokens so I'm creating my own. For those unfamiliar with ...
12
votes
3answers
3k views

Random Number Generator Class

I've written an abstract class in C# for the purpose of random number generation from an array of bytes. The .NET class RNGCryptoServiceProvider can be used to ...
13
votes
1answer
762 views

Quasi-random sequences: how to improve style and tests?

The requirements for this one were (original SO question): Generate a random-ish sequence of items. Sequence should have each item N times. Sequence shouldn't have serial runs longer than a given ...
8
votes
1answer
2k views

Randomly sampling a population and keeping means: tidy up, generalize, document?

This is part from an answer to a Stack Overflow question. The OP needed a way to perform calculations on samples from a population, but was hitting memory errors due to keeping samples in memory. ...
19
votes
3answers
2k views

Shuffling algorithm for a “guess that tune” game

I'm making a "guess that tune" game in Visual Basic 6 that is supposed to play each song in a random order: ...
12
votes
4answers
388 views

Draw random 1's and 0's

I was wondering if anyone would be so kind as to look at this code I've written for practice. Tell me what am I doing wrong, where can I optimize, anything. What this code does is (in terminal) draw ...

1
10 11 12 13
14