random

Randomize matrix in perl, keeping row and column totals the same

I have a matrix that I want to randomize a couple of thousand times, while keeping the row and column totals the same: 1 2 3 A 0 0 1 B 1 1 0 C 1 0 0 An example of a valid random matrix would be: 1 2 3 A 1 0 0 B 1 1 0 C 0 0 1 My actual matrix is a lot bigger (about 600x600 items), so I really nee...

PostgreSQL: change date by the random number of days

How can I change the date by the random number of days in PostgreSQL? Unfortunately http://stackoverflow.com/questions/1400505/postgresql-random-number-range-1-10 solution with trunc doesn't work: select date(now()) + (trunc(random() * 20)) results in: ERROR: operator does not exist: date + double precision LÍNEA 1: select date...

how to check repetition of numbers in an array?

I generate random numbers and store them in an array. int RandomNumber = arc4random() % 12; [NSMutablearray *Number addObject:[NSNumber numberWithInt:RandomNumber]]; Now i want to make sure the same number is not created randomly again. Can any one please tell me how to do it with sample code. ...

What's the easiest way to reproduce a randomly generated level in Python?

I'm making a game which uses procedurally generated levels, and when I'm testing I'll often want to reproduce a level. Right now I haven't made any way to save the levels, but I thought a simpler solution would be to just reuse the seed used by Python's random module. However I've tried using both random.seed() and random.setstate() and ...

Write a truly inclusive random method for javascript

Javascript's MATH object has a random method that returns from the set [0,1) 0 inclusive, 1 exclusive. Is there a way to return a truly random method that includes 1. e.g. var rand = MATH.random()*2; if(rand > 1) { rand = MATH.floor(rand); } return rand; While this always returns a number from the set [0,1] it is not truly ran...

Php/MySQL help - random daily pick?

Hello, I'm trying to get a pick from my DB that would last for a day (daily pick). I use the following code: $query = 'SELECT * FROM table ORDER BY rand() LIMIT 1 But as you can see it only gives me a random pick from the table, and every time I refresh the page it gets me a new random pick. How can I make the pick to last for a whole...

C#/Java Number Randomization

Is it possible, from .NET, to mimic the exact randomization that Java uses? I have a seed, and I would like to be able to recieve the same results in both C# and Java when creating a random number. ...

Randomly Generate Letters According to their Frequency of Use?

How can I randomly generate letters according to their frequency of use in common speech? Any pseudo-code appreciated, but an implementation in Java would be fantastic. Otherwise just a poke in the right direction would be helpful. Note: I don't need to generate the frequencies of usage - I'm sure I can look that up easily enough. ...

How do I access random element in a Perl DBM hash?

I have a Perl DBM hash containing a list of URLs that I want to pick randomly from to load balance spidering sites. As a result I want to pick a key at random, or select the nth element (so I can randomise n). I'm aware this goes against the concept of a hash, but is this possible? NOTE: missed a valuable point that hash size will be ...

How can I shuffle the lines of a text file in Unix command line?

I searched SO for a similar Q/A to no avail. I want to shuffle the lines of a text file randomly and create a new file. The file may have several thousands of lines. How can I do that with cat, awk, cut, etc.? ...

Looking for PRNG that you can seed with any number bytes

I'm looking for a PRNG (pseudo randomness) that you initially seed with an arbitrary array of bytes. Heard of any? ...

How do I make a page generate and display four random numbers in the 0 to 9 range?

<html> <body> <div style="text-align:center"><h2>Lucky Mo's Gift to You</h2> <p>Numbers rule our lives. If you would like the benefit of Lucky Mo's amazing powers of prognostication, click on the button below to receive your guaranteed lucky number of the day!</p> <input type="button" value="Click Here For Today's Pick-4 Winner" oncli...

randomly generate 40 questions in vb6? please help me

i've been trying to create a vb6 code that will randomize 10 questions but it's not working. i use sql as my database here's my code: Private Sub cmdNext_Click() Dim real_ans As String Dim nCnt As Integer 'nCnt = nCnt + 2 'Label3.Caption = nCnt real_ans = Adodc1.Recordset.Fields("answer") With Adodc2.Recordset Dim grade As String If...

Generating a probability distribution

Given an array of size n I want to generate random probabilities for each index such that Sigma(a[0]..a[n-1])=1 One possible result might be: 0 1 2 3 4 0.15 0.2 0.18 0.22 0.25 Another perfectly legal result can be: 0 1 2 3 4 0.01 0.01 0.96 0.01 0.01 How can I generate these easily and quick...

Seeding SQLite RANDOM()

Does SQLite support seeding the RANDOM() function the same way MySQL does with RAND()? $query = "SELECT * FROM table ORDER BY RAND(" . date('Ymd') . ") LIMIT 1;"; From the MySQL Manual about RAND(N): If a constant integer argument N is specified, it is used as the seed value, which produces a repeatable sequence of column va...

JavaScript expression to generate a 5-digit number in every case

Hey, for my selenium tests i need an value provider to get a 5-digit number in every case. The problem with javascript is that the api of Math.random only supports the genration of an 0. starting float. So it has to be between 10000 and 99999. So it would be easy if it would only generates 0.10000 and higher, but it also generates 0.01...

python random.random()

Does python's random.random() ever return 1.0 or it only returns up until 0.9999..? ...

How to generate a good random seed to pass to srand()?

Hi, I am writing a C++ program which needs to create a temporary file for its internal usage. I would like to allow concurrent executions of the program by running multiple proccesses, so the temporary file name needs to be randomized, that way each spawned process will generate a unique temporary file name for its own use. I am using r...

How do I play a tone in Linux using C?

I'm trying to write a program to randomly generate music based on a simple set of rules. I would like the program to be able to generate its own sounds, as opposed to having a file with audio for each note. Does anyone know a simple way of doing this? It would be nice (but not essential) for the sound to be polytonal, and I would like a ...

Using random value as join condition

I am generating some test-data and use dbms_random. I encountered some strange behavior when using dbms_random in the condition of the JOIN, that I can not explain: ------------------------# test-data (ids 1 .. 3) With x As ( Select Rownum id From dual Connect By Rownum <= 3 ) ------------------------# end of test-data Select x.id, ...