random

easy way to randomize the entries of an array using stl?

Hi, I can sort a int* array using stl, plain and simple like std::sort(myarray, myarray + size); Is there any equal simple way to randomize it? thanks ...

jQuery pick next div in a list to show

Hey, I have some jQuery going here: $('#ticker1').hide(); $('#ticker2').hide(); $('#ticker3').hide(); $("#ticker").oneTime(2000,function(i) { /* Do the first pull out once */ var randomNum = Math.floor(Math.random()*3); /* Pick random div to show */ $('div#ticker div:eq(' + randomNum + ')').show(); $("#ticker").animate({...

What's a good way to select a random set of twitterers?

Considering the set of Twitter users "nodes" and the relation u follows v as the "edges", we have a graph from which I would like to select a subset of the users at random. I could be wrong, but from reading the API docs I think it's impossible to get a collection of users except by getting the followers or friends of an already-known us...

How to generate random numbers at set time intervals?

I have developed code in Java for generating ten random numbers from a range 0 to 99. The problem is I need to generate a random number for every 2 min. I am new to this area and need your views. ...

cocoa touch: rand() returning the same string

Here's my code: -(void)randommoves { NSArray *possiblemoves =[NSArray arrayWithObjects:@"R ",@"R' ",@"L ",@"L' ",@"B ",@"B' ",@"F ",@"F' ",@"U ",@"U' ",@"D ",@"D' ", nil]; NSMutableString *finalmoves = [[NSMutableString alloc] init]; finalmoves = [NSMutableString stringWithCapacity:0]; [finalmoves retain]; int i = 0; for (i=0; i<20; i...

ANSI C: How to split a string by newline and get a random line

Hi, I'm a new to C and got stuck with subj. I can split string with strtok but I don't know how to get a random token. Thanks. ...

Independent instances of 'random'

The below code attempts to illustrate what I want. I basically want two instances of "random" that operate independently of each other. I want to seed "random" within one class without affecting "random" in another class. How can I do that? class RandomSeeded: def __init__(self, seed): import random as r1 self.random...

Getting a random number between 0 and 0.06 in Java?

How do you get random Double values between 0.0 and 0.06 in Java? ...

Will using modulus favour high numbers?

Will adding 6 random unique numbers in the range 0-32 and doing a modulus on the result favour a high number? Example: 9 +10 +11 +18 +25 +28 +32 = 133 % 20 = 13 ...

How do I pass a C++0x random number generator to a function?

Do they all inherit from a base class? Do I have to use templates? (I am referring to these http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c15319/) I am doing this right now: typedef std::mt19937 RNG; and then class Chooser { public: Chooser(RNG& rng, uint n, uint min_choices, uint max_choices): In other words, I'm ...

Java algorithm for random class that chooses from two loops.

I have to make my program choose randomely between two sets of numbers (original & complement) but there are 5 sets of this loops. How can i assign for the program to choose randomely between the two (original &complement) in each set? ok so this is what i have so far... import java.util.Scanner; import java.util.Random; public class ...

Random number to pick an image Xcode iPhone

I've been searching all over the net for an answer to this one! Hoping one of you can help me. So far I have a button that produces a random nr between 1 and 6 in a label. Then I want a picture to appear depending on what nr is in the label. For example: If the number 1 is generated, I want img1.png to appear in a UIImageV...

C++ How I can get random value from 01 to 12?

Hi How I can get in C++ random value from 01 to 12? So I will have 03, or 06, or 11? ...

python random string generation with upper case letters and digits

Hello, I want to generate string with N size. It should be made up of numbers and upper case english letters such as: 6U1S75 4Z4UKK U911K4 How can I achieve this in a pythonic way ? Thanks ...

Random items in Prolog

I know I can do X is random(10). to get a random number from 0 to 10, but is there a similar command to get a random matching item? ...

Random MySQL row while avoiding holes

I have a big MySQL users table and need to get six random rows from it (I'm using PHP). The table has an index column that is auto incremented. The only problem is that some rows are marked as inactive, because some users have disabled their accounts or whatever. That means I can't just count the rows and then grab a random number from t...

Select random row from an sqlite table.

I have an sqlite table with the following schema: CREATE TABLE foo (bar VARCHAR) I'm using this table as storage for a list of strings. How do I select a random row from this table? ...

Random number in iphone sdk?

How do you generate a random number when a button is clicked, and depending on that number, different actions take place. I probably only need a random number from 1-10. -(IBACTION)buttonClicked{ "generate the random number" if(number == 1){ something happens } else if(number == 2){ somethine else happens } etc } ...

How to get 2 random (different) elements from a c++ vector

I would like to get 2 random different elements from an std::vector. How can I do this so that: It is fast (it is done thousands of times in my algorithm) It is elegant The elements selection is really uniformly distributed ...

How to generate a random BigInteger value in Java?

I need to generate arbitrarily large random integers in the range 0 (inclusive) to n (exclusive). My initial thought was to call nextDouble and multiply by n, but once n gets to be larger than 253, the results would no longer be uniformly distributed. BigInteger has the following constructor available: public BigInteger(int numBits, R...