How to sort a NSArray randomly?
Let's say I have a NSArray with 50-100 objects inside. How can I sort the array into a random order? ...
Let's say I have a NSArray with 50-100 objects inside. How can I sort the array into a random order? ...
I would like to parallelize my boost random number generator code in C++ with OpenMP. I'd like to do it in way that is both efficient and thread safe. Can someone give me pointers on how this is done? I am currently enclosing what I have below; this is clearly not thread safe since the static variable in the sampleNormal function is like...
How do I display a random set of list items, I think I have this down. Thanks! //Count the number of li's in the object var listCount = $("li.contentBlock", obj).length; //Generate a random number from the count of li's var randomListNumber = Math.floor(Math.random() * listCount -1); //Gener...
Hi, I'm trying to create a random float between 0.15 and 0.3 in Objective-C. The following code always returns 1: int randn = (random() % 15)+15; float pscale = (float)randn / 100; What am I doing wrong? ...
I want to generate (an image of) a single branch of a tree (the "woody plant" kind). Maybe similar to this branch, or this one. I need it to be interesting but simple, so just one branch, with a few turns, and only a few splits (where it changes from one limb into two). It should start with one fat branch and split off into a few thin b...
i would like to make a list of names and then make a random selection but all of them should be called. off course not repeated. delphi code ...
I understand, using srand(time(0)), helps in setting the random seed. However, the following code, stores the same set of numbers for two different lists. Wondering, how do I generate the different set of numbers when the following function gets called more than once. void storeRandomNos(std::list<int>& dataToStore) { int noofElem...
I would like to be able to create a page using HTML and scripts to display text in which each character is of a different randomly generated color. With a javascript graphics library that supports the creation and use of RBG colors and the Math.random() method, it is simple to make randomly colored lines/shapes/etc, but I do not know ho...
Let us assume we're generating very large (e.g. 128 or 256bit) numbers to serve as keys for a block cipher. Let us further assume that we wear tinfoil hats (at least when outside). Being so paranoid, we want to be sure of our available entropy, but we don't entirely trust any particular source. Maybe the government is rigging our coins...
Here is the description of the the problem Given an integer N, write a function which returns an integer array of size N, containing the numbers from 1 to N in a random order. Each number from 1 to N must appear once and must not repeat. What is the running time of your algorithm? Can your algorithm be improved? For example: if you ...
I am trying to implement a generation of HttpSession key I am generating a random number between 1,000,000 to 9,999,999 and send it as a cookie to the user. Is it possible to make this process secure? anyone can make a random number like that and try to access my server...maybe I need larger range? another question is, how can I gener...
Hi, I'm wondering how I could have a JavaScript image rotator/slideshow, that each time it displays each image (for 5 seconds), it refreshes from the last time it has shown. Also, as something else, but not requiered, I was wondering if it was possible to have a drop-down list of the image locations down the bottom (there are 12 images)...
Possible Duplicate: Create Random Number Sequence with No Repeats I'm trying to generate unique session IDs. Each session ID is a random integer. The main requirement is that each session ID is unique. I'm trying to find the most efficient algorithm to do this. Scenario: Generate 10 random numbers from 1 to 10 inclusive. My...
MySQL what's the best way to select X random entries (rather than just one) - optimization for heavy use, i.e. on main page of a domain. Supposedly just blindly using MySQL rand() is going to make this rather scary for large databases - please give me a better optimization answer than that! ...
Does anyone have a simple shell script or c program to generate random files of a set size with random content under linux? ...
This is my first Perl script. Ever: #!/usr/bin/perl if ($#ARGV < 1) { die("usage: <size_in_bytes> <file_name>\n"); } open(FILE,">" . $ARGV[0]) or die "Can't open file for writing\n"; # you can control the range of characters here my $minimum = 32; my $range = 96; for ($i=0; $i< $ARGV[1]; $i++) { print FILE chr(int(rand($range)...
I need to to generate 6 unique random numbers from 1 to 37; At first I used a simple array mapping: private int k=6, n=37; public int[] Results () { // fill an array with numbers 1 2 3 . . . n int[] numbers = new int[n]; for (int i = 0; i < numbers.length; i++) numbers[i] = i + 1; // draw k numbers and put them...
I want to generate a large (~2 kb), random, unique block of random text for use as an authentication token. Standard hashing functions produce results that are too short. Would it be OK to use openssl's private key generation function or is there more appropriate solution I should look at? ...
I am currently working with PHP code that random selects colors: <div onclick="location.href='<?php the_permalink() ?>';" style="cursor:pointer;background:#<?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php echo rand(0, 9); ?><?php ...
Hi, I'm trying to load a random UIImage from the web using this method NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadImage) ...