This tag is for questions pertaining to random numbers, whether pseudo random or truly random.
1
vote
2answers
45 views
Shuffling algorithm suitable?
Just checking that this shuffling algorithm is suitable. Or maybe there could be improvements?
public static void shuffleArray(Object[] arr, Random rnd){
int lastIndex = arr.length - 1;
for ...
1
vote
0answers
65 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 properties. Still, it's easy to get things wrong (uniform sampling where ...
1
vote
1answer
93 views
PHP: Random imgur image loader
Just a little thing I made to load 20 random images from imgur. I looked at the way that imgur references images on its site, and I felt like I could probably generate a random string of letters and ...
2
votes
1answer
45 views
Generating random strings
I've created the following string manipulation function for randomizing my passed string in Lua:
require "string"
require "math"
math.randomseed( os.time() )
function string.random( self )
...
0
votes
2answers
88 views
How to take the some elements of a list of random numbers and sort them?
I want to create a file consisting take rows of distinct numbers in ascending order. They are randomly taken from the first total integer. The file will be used to make an excerpt as discussed here.
...
1
vote
4answers
98 views
Can you review my random number wrapper class
I made this class to handle any min max integer value and return a random number in the entered parameter range. I tested it to work with all combinations(I think). But is this totally wrong or ...
3
votes
2answers
141 views
Generating random sequences while keeping sum fixed
The output is a random sequence, and the input is the sum of the sequence.
My solution is generating a random number *rand_num* from (0, sum_seq) at first, then draw another number randomly from (0, ...
1
vote
3answers
112 views
What is wrong with my Genetic Algorithm?
I am trying to understand how genetic algorithms work. As with everything, I learn by attempting to write something on my own;however, my knowledge is very limited and I am not sure if I am doing this ...
3
votes
3answers
136 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 .times method in place of the while code blocks to increase ...
1
vote
1answer
76 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 equivalent to discrete pdf.
Can you anticipate any issue with this snippet? ...
1
vote
0answers
107 views
Review: C++ Algo - Function
See Review: C++ Algo - Style
I'm looking for a review of the function of this code, answers to the above question which also describes the code use focus on style instead.
Below is the updated code ...
3
votes
2answers
195 views
Review: C++ Algo - Style
Can this code be reviewed?
I've updated this question to be about code style only, as all of its answered focused on this aspect. For the codes function, see Review: C++ Algo - Function
'algo' is an ...
4
votes
3answers
128 views
Extending java.util.Random.nextInt(int) into nextLong(long)
In java.util.Random the Oracle implementation of nextInt(int) is as follows:
public int nextInt(int n) {
if (n <= 0)
throw new IllegalArgumentException("n must be positive");
if ...
8
votes
1answer
100 views
Creating random maze in Go
/*
Create a random maze
*/
package main
import (
"fmt"
"math/rand"
"time"
)
const (
mazewidth = 15
mazeheight = 15
)
type room struct {
x, y int
}
func (r room) ...
6
votes
4answers
278 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.
/*===================================*
* Compile it to produce Shuffle.exe *
* ...
0
votes
4answers
127 views
Random “month & day” with JS ( jQuery )
setInterval(function() {
var days_array = [31,29,31,30,31,30,31,31,30,31,30,31];
var m = randNum(12);
var m_limit = days_array[m-1];
var d = randNum(m_limit);
$("code").html("day = ...
2
votes
1answer
189 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 ...
2
votes
0answers
120 views
Would someone please critique this mips program?
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
3answers
152 views
Need advice regarding Style and Flow in C++ (Simple randomization program)
I come here humbly asking for advice from those with more experience than I. I believe this is a novice question but I hope it is useful to others. I'm a few months into learning C++ programming and I ...
1
vote
2answers
114 views
Haskell: rndFile and [Char] vs IO String error
import System.Environment (getArgs)
import Random
main = do
args <- getArgs
let len = length args
let n = if len < 1 then 10000 else read (args !! 0) :: Int
let fileName = if len < ...
1
vote
3answers
1k 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
168 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 ...
3
votes
2answers
433 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:
byte[] GetRandomBytes(int count) -> int NextInteger(int min, int max)
Another way to think about ...
2
votes
2answers
581 views
Random string + encrypt/decrypt
Are there any security flaws in what I plan to do?
I need to store in my DB the following:
a random string to act as a salt for encrypting a password
the encrypted password that used the salt in #1
...
10
votes
8answers
5k views
Random string generation
I'm using this C# function, to generate random coupons for a system. How can I improve it?
public static string GenerateCoupon(int length)
{
string result = string.Empty;
Random random = new ...
2
votes
1answer
760 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".
var FISH = {
"level1": [
//["name", xp, ...
1
vote
2answers
301 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 ...
7
votes
1answer
3k 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 ...
9
votes
3answers
1k 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 generate this array of random bytes, for ...
8
votes
1answer
466 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 ...
5
votes
1answer
753 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.
...
9
votes
3answers
862 views
Is this shuffling algorithm OK?
I'm making a "guess that tune" game in Visual Basic 6 that is supposed to play each song in a random order. Here is my code to do so:
' from frmGuessGame.frm
Private Sub Swap(ByRef Value1 As Variant, ...
