random

C++ function for picking from a list where each element has a distinct probability

I have an array of structs and one of the fields in the struct is a float. I want to pick one of the structs where the probability of picking it is relative to the value of the float. ie struct s{ float probability; ... } s sArray[50]; What is the fastest way to decide which s to pick? Is there a function for this? If I knew ...

Actionscript-3 random numbers between max and min...

hi, I'm generating a random number between min and max with this code: return min + (max - min) * Math.random(); And it works. However, the random numbers are very little usually between "1 or 3" even if the max is 80. How can I better distribute the random numbers over all range ? thanks ...

Go - Example about crypto/rand

Could put a little example about the use of crypto/rand [1]? The function Read has as parameter an array of bytes. Why? If it access to /dev/urandom to get the random data. func Read(b []byte) (n int, err os.Error) [1] http://golang.org/pkg/crypto/rand/ ...

How does MySQL's ORDER BY RAND() work?

Hi, I've been doing some research and testing on how to do fast random selection in MySQL. In the process I've faced some unexpected results and now I am not fully sure I know how ORDER BY RAND() really works. I always thought that when you do ORDER BY RAND() on the table, MySQL adds a new column to the table which is filled with rando...

RANDOM Number Generation in C

Recently i have begun development of a simple game. It is improved version of an earlier version that i had developed. Large part of the game's success depends on Random number generation in different modes: MODE1 - Truly Random mode myRand(min,max,mode=1); Should return me a random integer b/w min & max. MODE2 - Pseudo...

How to generate random number with the specific length in python

Let say I need a 3 digit number, so it would be something like: >>> random(3) 563 or >>> random(5) 26748 >> random(2) 56 ...

How to choose a random record out of the greatest N records efficiently(not using sub query) in MySQL?

select .. from ( Select ... from ... order by weight desc limit N ) order by rand() limit 1 The above needs to create a temporary table each time,which is not efficient,so it doesn't qualify. How to do it properly? ...

random data using php & mysql

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT NULL auto_increment, title text NULL, tags text NULL, PRIMARY KEY (id) ); data on field tags is stored as a comma separated text like html,php,mysql,website,html etc... now I need create an array that contains around 50 randomly selected tags...

Getting a "for each" loop in Java to run in different order everytime

Hi, Basically my problem is that I'm trying to write a method that finds a random path in a graph of strings, which takes as it's parameters a start string, an integer length and a Vector of strings that will store the path. I'm attempting to do this by first adding the starting string to our blank vector, recursing through its neighbor...

How to randomize a sorted list?

Here's a strange question for you guys, I have a nice sorted list that I wish to randomize. How would i go about doing that? In my application, i have a function that returns a list of points that describe the outline of a discretized object. Due to the way the problem is solved, the function returns a nice ordered list. i have a secon...

Whats wrong with my Random?

Here's my import statement: import java.util.*; Here it is in main: Random Rand = new Random() ; Here it is in a public void method : int a = 0 ; while (!done) { int a = Rand.nextInt(10) ; if (debug) stuff ; if (possibles[a]==1) done = true ; ...

PHP Get random paragraph

Anyone know how to get a random set of lines from a text file? I want to get a set of 3 lines with <br> on the front of each and display them through html. example: set 1 <br>Hi <br>what's your name <br>goodbye set 2 <br>stack <br>overflow <br>hi there set 3,4,5.... Choose one random set and display it. The sets of lines would be...

Random number generation

I am using below code to generate random numbers in range... int randomNumberWithinRange(int min,int max) { int snowSize = 0; do { snowSize = rand()%max; } while( snowSize < min || snowSize > max ); return snowSize; } for(int i = 0; i < 10 ; i++) NSlog("@"%d",\t", rando...

generate random double numbers in c++

how to generate random numbers between two doubles in c++ , these number should look like xxxxx,yyyyy . thanks ...

Openssl RAND_bytes algorithm

What algorithm use RAND_bytes function in openssl? ...

Fastest Way to generate 1,000,000+ random numbers in python

I am currently writing an app in python that needs to generate large amount of random numbers, FAST. Currently I have a scheme going that uses numpy to generate all of the numbers in a giant batch (about ~500,000 at a time). While this seems to be faster than python's implementation. I still need it to go faster. Any ideas? I'm open to w...

Drupal 6: getting random data from database

Hi friends, I spend few hours at google, but cant find :/ is it possible to get a random data from database with Drupal 6? appreciate helps!! thanks! ...

Visual Basic Express 2008 Help

I have been given a task to: Develop a program where a child will be presented with picture of a fruit (one of five possible fruit) on the screen at the click of a start button. The child will then try to recognise the fruit and write its name in a specified place on the screen. On the click of a check button the name of the fruit writt...

Random encounter not so random

Hello i am having some problems generating random numbers with C# Now i have this function. public Color getRandomColor() { Color1 = new Random().Next(new Random().Next(0, 100), new Random().Next(200, 255)); Color2 = new Random().Next(new Random().Next(0, 100), new Random().Next(200, 255)); Color3 = new Random().Next(new Ran...

.NET: will Random.Random operate differently inside a static method

I am having difficulty with the following code which is inside a static method of a non-static class. int iRand; int rand; rand = new Random((int)DateTime.Now.Ticks); iRand = rand.Next(50000); The iRand number, along with some other values, are being inserted into a new row of an Access MDB table via OLEDB. The iRand number is being...