random

JUnit Test method with randomized nature

Hey, I'm working on a small project for myself at the moment and I'm using it as an opportunity to get acquainted with unit testing and maintaining proper documentation. I have a Deck class with represents a deck of cards (it's very simple and, to be honest, I can be sure that it works without a unit test, but like I said I'm getting u...

Generating two differnet pseudorandom numbers using the same seed

Is it possible to generate two different psuedorandom numbers on two separate program runs without using time as the seed? i.e. using the same seed on both runs, is it possible to get two different numbers? ...

PHP: read all files but randomly?

hi there, i wonder if there's a way of reading a directory in a random order. With the following code i'm running through the directory thumbs and it's printing images on my website. However, they are always read alphabetically and i wonder if there's a way in doing this randomly? <?php $path = 'thumbs'; if ($handle = opendir($path)) ...

Making more recent items more likely to be drawn

There are a few hundred of book records in the database and each record has a publish time. In the homepage of the website, I am required to write some codes to randomly pick 10 books and put them there. The requirement is that newer books need to have higher chances of getting displayed. Since the time is an integer, I am thinking like...

Is there a random sampling function for iphone development that can simulate a coin toss?

Is there a random sampling function for the iphone? For example, if you want to flip a coin that returns heads 25% of the times it's flipped, and you want to flip it and see if you get heads this time? I googled for random sampling probability for iphone and couldn't find anything. ...

ranged random numbers in C

Possible Duplicate: How to generate a random number from within a range - C I'm looking for something I can use in C that will give me a random number between a and b. So something like rand(50) would give me a number between 1 and 50. ...

Weighted random numbers in MATLAB

How to randomly pick up N numbers from a vector a with weight assigned to each number? Let's say: a = 1:3; % possible numbers weight = [0.3 0.1 0.2]; % corresponding weights In this case probability to pick up 1 should be 3 times higher than to pick up 2. Sum of all weights can be anything. ...

Is there a more efficient way to organize random outcomes by size in Python?

(sorry if this is a dumb question, I'm still learning) I'm making a program that, for part of the prog, rolls four dice and subtracts the lowest dice from the outcome. The code I'm using is die1 = random.randrange(6) + 1 die2 = random.randrange(6) + 1 die3 = random.randrange(6) + 1 die4 = random.randrange(6) + 1 if die1 <= die2 and die...

Pairing Links with PHP Randomized Ads

So I have the following code with works great for randomly generating position for 5 different sidebar ads, my problem is how to give the ads a link that will always be paired with them. I'm looking for suggestions from some PHP gurus as to best practices for doing this... <ul class="top_ads"> <?php ...

How many double numbers are there between 0.0 and 1.0?

This is something that's been on my mind for years, but I never took the time to ask before. Many (pseudo) random number generators generate a random number between 0.0 and 1.0. Mathematically there are infinite numbers in this range, but double is a floating point number, and therefore has a finite precision. So the questions are: J...

How to always return a set number of records when using find_related_tags with acts-as-taggable-on

I'm using the acts-as-taggable-on gem and I need to use find_related_tags on my survey model to get back 3 surveys every time. In the event there aren't always 3 related I need to pick how ever many are related plus some random ones to get to 3. Additionally I have a method I wrote called completed_survey_ids which return an array of s...

module "random" not found when building .exe from IronPython 2.6 script

I am using SharpDevelop to build an executable from my IronPython script. The only hitch is that my script has the line import random which works fine when I run the script through ipy.exe, but when I attempt to build and run an exe from the script in SharpDevelop, I always get the message: IronPython.Runtime.Exceptions.ImportException...

REST - get a random number GET or POST?

How should a random number generator properly be implemented in REST? GET RANDOM/ or.. POST RANDOM/ The server returns a different random number each time. I can see arguments for both ways. ...

jQuery: how to pick unique IDs ?

Hello. New to whole this jQuery (and javascript altogether, heh) and so far it's been excellent, but now I'm in a small pickle. Let's say I have list of forms generated from SQL database and every single one of them has to have unique id, so how I can select the specific item that is to be manipulated (changing values via php). the $("#...

rng random number

Hi, I have a question. How can I calculate/estimate upper bound of random number, that a random number can generate ? Thanks in advance! ...

Multi-threaded random_r is slower than single threaded version.

The following program is essentially the same as the one described here. When I run and compile the program using two threads (NTHREADS == 2), I get the following run times: real 0m14.120s user 0m25.570s sys 0m0.050s When it is run with just one thread (NTHREADS == 1), I get run times significantly better even th...

java random percentages

I need to generate n percentages (integers between 0 and 100) such that the sum of all n numbers adds up to 100. If I just do nextInt() n times, each time ensuring that the parameter is 100 minus the previously accumulated sum, then my percentages are biased (i.e. the first generated number will usually be largest etc.). How do I do t...

Sample uniformly at random from an n-dimensional unit simplex.

Sampling uniformly at random from an n-dimensional unit simplex is the fancy way to say that you want n random numbers such that they are all non-negative, they sum to one, and every possible vector of n non-negative numbers that sum to one are equally likely. In the n=2 case you want to sample uniformly from the segment of the line ...

Php random row help...

I've created some code that will return a random row, (well, all the rows in a random order) But i'm assuming its VERY uneffiecent and is gonna be a problem in a big database... Anyone know of a better way? Here is my current code: $count3 = 1; $count4 = 1; //Civilian stuff... $query = ("SELECT * FROM `*Table Name*` ORDER BY `Id` ASC"...

Get random enum from a select group

Given a group of about 20 enums that I cannot modify. Im looking for an elegant solution to generate a random enum from a specific sample (ie, 2, 7, 18) I could put these into an arraylist, but thought I would ask if there is something else I could try. ...