random-numbers

Best way to calculate if there is a 1/4 chance something will happen in C++?

Hi, I was wondering if there is a smart way to find out There is a 1/4 chance something happens. I know we can do this with rand() % 4 and checking if it is equal to 0, but is there a way without using rand()? In c++, thanks. ...

Is it possible to generate random numbers through physical process simulation?

Is it possible to generate random numbers through physical process simulation? If I simulate the physical roll of a dice (i.e. you picking it up, shaking it in your hand, releasing it onto the table and recording which side ends up "up"...) will that produce a "random" number or would I just have a complex simulation which really accomp...

Java Generator for Poisson and Uniform Distributions?

From what I understand, the standard generator is for the Normal Distribution. I have to generate random numbers according to the Normal, Uniform and Poisson Distributions, but I can't seem to find a class for the last 2. I have to generate them in the range of 0 - 999999. ...

Non-repetitive random number C#

To generate Random numbers from 1- 20 I need to pick selective and it should not be repetitive. How to do this in C# Note I need to loop through as like this Random rnd = new Random() rnd.Next(1,20) for(int i =0; i<=20;i++) { } For all the loops number should be 1 to 20 ...

Get random number that does/doesn't match criteria (PHP)

Using PHP (other languages, using common built-ins are welcome), how can I get a random (or pseudo-random) number that does NOT match a certain criteria? IE: I want $x = rand(0, 99) but only if ($x % 9) != 0. What is a clean acceptable way to constrain random numbers to a criteria like that? As an example, using a while() loop, and p...

Why do you use a random number generator/extractor?

Hi, I am dealing with some computer security issues at the school at the moment and I am interested in general programming public preferences, customs, ideas etc. If you have to use a random number generator or extractor, which one do you choose? Why do you choose it? The mathematical properties, already implemented as a package or for w...

Random.Next returns always the same values

This is really weird, and I cannot see why this is happening. In the foreach cycle, I am iterating through a class A collection, and for each class, I call the Count() method, where r1 and r2 numbers are generated from range [-1,1]. The problem is that Random.Next returns the same "random" numbers for each instance. When the results for...

Random sudoku generation

I'm writing a function that should generate random sudoku puzzles for a simulation project; this funcion takes as argoument the number of cells to generate then it generates the indexes of cells and numbers to put in those cells. I have a problem in generation of cells indexes, I'm not an expert in programming and i can't find a good ro...

How do I get the text-form verification code when doing auto site access in Perl?

I'm playing around with Win32::IE:Mechanize to try to access some authentication-required sites automatically. So far I've achieved moderate success, for example, I can automatically log in to my yahoo mailbox. But I find many sites are using some kind of image verification mechanism, which is possibly called CAPTCHA. I can do nothing to...

filling an array with random number

Hi there, I trying to fill an array of 20 ints with numbers from 1-20 in random sequence. here's my code: int lookup[20]={0}; int array[20]={0}; srand(time(NULL)); for(int i=0;i<20;++i){ bool done=false; while(!done){ int n=rand()%20; if(lookup[n]==0){ array[i]=n; lookup[n]=1; done...

How to generate a random number, then display it on screen?

Ok, im fairly new to android but i have managed to teach myself the basics, i am making an app where you press a button , and a new screen opens and it shows a randomly generated number, the only problem is i dont know how to generate and display the random number, i have been searching the web for ages and have only found little snippet...

Random Number generator function ran2 Numerical Recipes

Hi, Given that we start the call to the function ran2 with a negative integer [the seed] it will produce a series of random numbers. The sequence can be regenerated exactly if the same seed is used. Now my question is that is there a way that we can directly enter into some point in the sequence and then continue from that point onwar...

How can I efficiently select several unique random numbers from 1 to 50, excluding x?

I have 2 numbers which are between 0 and 49. Let's call them x and y. Now I want to get a couple of other numbers which are not x or y, but are also between 0 and 49 (I am using Objective C but this is more of a general theory question I think?). Method I thought of is: int a; int b; int c; do { a = arc4random() % 49; } while (...

Best way to store list of numbers and to retrieve them

Hi. What is the best way to store a list of random numbers (like lotto/bingo numbers) and retrieve them? I'd like to store on a Database a number of rows, where each row contains 5-10 numbers ranging from 0 to 90. I will store a big number of those rows. What I'd like to be able is to retrieve the rows that have at least X number in comm...

random number generation

How to generate random numbers using assembly code in the range 1--4 ? ...

C: Random Number Generation - What (If Anything) Is Wrong With This

For a simple simulation in C, I need to generate exponential random variables. I remember reading somewhere (but I can't find it now, and I don't remember why) that using the rand() function to generate random integers in a fixed range would generate non-uniformly distributed integers. Because of this, I'm wondering if this code might ha...

Smarty multiple random numbers list

Hey Stackoverflow-Folks, is there any smart way to post random numbers (e.g. 1-4) in a list by using the smarty tpl-engine? standart list sorted 1-5: <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> Here's my solution (PHP): <ul> {foreach from=randomNumbers} <li>{smarty.randomNumbers}</li> {/foreach} </ul>...

reservoir sampling problem

This MSDN article proves the correctness of Reservoir Sampling algorithm as follows: Base case is trivial. For the k+1st case, the probability a given element i with position <= k is in R is s/k. The probability i is replaced is the probability k+1st element is chosen multiplied by i being chosen to be replaced, which is: s/(k+1) * 1...

Getting N random numbers that the sum is M

Hello I want to get N random numbers that the sum of them is a value. For example, let's suppose I want 5 random numbers that their sum is 1 Then, a valid possibility is: 0.2 0.2 0.2 0.2 0.2 Other possibility is: 0.8 0.1 0.03 0.03 0.04 And so on. I need this for the creation of the matrix of belongings of the Fuzzy C-means. ...

Random numbers from -10 to 10 in C++

How does one make random numbers in the interval -10 to 10 in C++ ? srand(int(time(0)));//seed for(int i = 0; i < size; i++){ myArray[i] = 1 + rand() % 20 - 10;//this will give from -9 to 10 myArray2[i] =rand() % 20 - 10;//and this will -10 to 9 } ...