random

How to get a random number in Ruby?

In Ruby, how do you generate a random number between 0 and n? In .NET you can create a Random object, does something like this exist for Ruby? ...

quick selection of a random row from a large table in mysql

What is a fast way to select a random row from a large mysql table? I'm working in php, but I'm interested in any solution even if it's in another language. ...

Random Gaussian Variables

Hi there, does someone of you know if there is a class in the standard library of .net, that gives me the functionality to create random variables that follow a gaussian distribution? Greets Sebastian ...

Random Image as link associated with image

I'm looking for a script that will call a random image linked to its corresponding site on pageload. Anyone know a javascript or php way to do this? ...

What's the best way to return a random line in a text file using C?

What's the best way to return a random line in a text file using C? It has to use the standard I/O library (<stdio.h>) because it's for Nintendo DS homebrew. Clarifications: Using a header in the file to store the number of lines won't work for what I want to do. I want it to be as random as possible (the best being if each line has a...

How do I make a function happen 50% of the time in vb6

Making a small app, and I want a function to execute 50% of the time. So if I were to dbl click the exe half the time the function would execute, and the other half it wouldn't. I can't seem to find anyway to easily do this, the one solution I tried seemed to determine the chance on compile rather than on run. Thanks in advance! ...

random number with ratio 1:2

I have to generate two random sets of matrices Each containing 3 digit numbers ranging from 2 - 10 like that matrix 1: 994,878,129,121 matrix 2: 272,794,378,212 the numbers in both matrices have to be greater then 100 and less then 999 BUT the mean for both matrices has to be in the ratio of 1:2 or 2:3 what ever c...

Random points inside a Polygon

I have a 4 side convex Polygon defined by 4 points in 2D, and I want to be able to generate random points inside it. If it really simplifies the problem, I can limit the polygon to a parallelogram, but a more general answer is prefered. Generating random points until one is inside the polygon wouldn't work because it's really unpredict...

Simple Random Samples from a (My)Sql database

How do I take an efficient simple random sample in SQL? The database in question is running MySQL; my table is at least 200,000 rows, and I want a simple random sample of about 10,000. The "obvious" answer is to: SELECT * FROM table ORDER BY RAND() LIMIT 10000 For large tables, that's too slow: it calls RAND() for every row (which al...

Can one setup dev/random when using a VM(virtual machine)?

Does anyone know if it's possible to setup dev/random when running the OS within a VM (VMWare in this case)? ...

randomness

Hi Guys, I need some help regarding algorithm for randomness. So Problem is. There are 50 events going to happen in 8 hours duration. Events can happen at random times. Now it means in each second there is a chance of event happening is 50/(8*60*60)= .001736. How can I do this with random generation algorithm? I can get random number ...

Generate Random numbers uniformly over entire range

I need to generate random numbers with in specified interval [max,min] Also the random numbers should be uniformly distributed over interval, not located to particular point Currenly I am generating as: for(int i=0;i<6;i++) { DWORD random= rand()%(max-min+1) + min; } From my tests random numbers are generated around one point only ...

Running Time of Random Sort

How would you describe the running time of this sort, given a function sorted which returns True if the list is sorted that runs in O(n): def sort(l): while not sorted(l): random.shuffle(l) Assume shuffling is perfectly random. Would this be written in big-O notation? Or is there some other way of categorizing algorithms with ra...

SecureRandom: init once or every time it is needed?

Our team is using a SecureRandom to generate a list of key pairs (the SecureRandom is passed to a KeyPairGenerator). We cannot agree on which of the following two options to use: Create a new instance every time we need to generate a key pair Initialize a static instance and use it for all key pairs Which approach is generally bette...

System.Random keeps on returning the same value

I am using a System.Random object which is instantiated with a fixed seed all thoughout the application. I am calling the NextDouble method and after some time passed I am getting 0.0 as result. Is there any remedy to this, has anyone else encountered this ? EDIT: I have one seed for the whole run which is set to 1000 for convience sak...

How do I randomly select an item from a list using Python?

Let's say, as an example, I have the following list: foo = ['a', 'b', 'c', 'd', 'e'] What is the best way to retrieve an item at random from this list? ...

Generate distinctly different RGB colors in graphs

When generating graphs and showing different sets of data it usually a good idea to difference the sets by color. So one line is red and the next is green and so on. The problem is then that when the number of datasets is unknown one needs to randomly generate these colors and often they end up very close to each other (green, light gree...

Random Number Generator: Class level or Method level?

Hi! When using a Random Number Generator, which is the better way to use it for greater randomness of the new value: Have a method that instantiates a new instance of the RNG each time and then returns a value? Have an instance of the RNG at the class level, which is instantiated once in the Constructor, and all subsequent calls for a...

Algorithm for generating a random number

I'm looking to generate a random number and issue it to a table in a database for a particular user_id. The catch is, the same number can't be used twice. There's a million ways to do this, but I'm hoping someone very keen on algorithms has a clever way of solving the problem in an elegant solution in that the following criteria is met: ...

Recommended way to initialize srand?

I need a 'good' way to initialize the pseudo-random number generator in C++. I've found an article that states: In order to generate random-like numbers, srand is usually initialized to some distinctive value, like those related with the execution time. For example, the value returned by the function time (declared in heade...