random

Probability Random Number Generator

Let's say I'm writing a simple luck game - each player presses Enter and the game assign him a random number between 1-6. Just like a cube. At the end of the game, the player with the highest number wins. Now, let's say I'm a cheater. I want to write the game so player #1 (which will be me) has a probability of 90% to get six, and 2% to...

what is the probability that the next random number will equal current one?

if i do this in a worksheet: =RAND() i also specified that i want only 2 decimal places and for example let's say that rand() = 0.07 what is the probability that when i call this function again i will get 0.07 ?? i know that ideally if we assume 100% randomness, the answer would be 1/ (10 * 10) because there are only 100 possible c...

Java: How to check the random letters from a-z, out of 10 letters minimum 2 letter should be a vowels.

I am writing a program to validate the following scenarios: Scenario 1: I am using the Random class from java.util. The random class will generate 10 letters from a-z and within 10 letter, minimum 2 letters must be a vowels. Scenario 2: When the player 1 and player 2 form a word from A-Z, he will score some points. There will be a s...

C++ Draw program, split in groups of two

I would like to make a draw application. I want to enter user names until eg "end" is entered and then the program to split them in groups of two. Can you suggest any examples? I don't know how to start! If possible, I want to be Cross-platform. If it isn't possible I want linux. ...

non-uniform distributed random array

Dear all, I need to generate a vector of random float numbers between [0,1] such that their sum equals 1 and that are distributed non-uniformly. Is there any python function that generates such a vector? Best wishes ...

rand() generating the same number – even with srand(time(NULL)) in my main!

So, I'm trying to create a random vector (think geometry, not an expandable array), and every time I call my random vector function I get the same x value, though y and z are different. int main () { srand ( (unsigned)time(NULL)); Vector<double> a; a.randvec(); cout << a << endl; return 0; } using the function //r...

What's going on here? Repeating rows in random list of lists.

I expected to get a grid of unique random numbers. Instead each row is the same sequence of numbers. What's going on here? from pprint import pprint from random import random nrows, ncols = 5, 5 grid = [[0] * ncols] * nrows for r in range(nrows): for c in range(ncols): grid[r][c] = int(random() * 100) pprint(grid) Examp...

Random select is not always returning a single row.

The intention of following (simplified) code fragment is to return one random row. Unfortunatly, when we run this fragment in the query analyzer, it returns between zero and three results. As our input table consists of exactly 5 rows with unique ID's and as we perform a select on this table where ID equals a random number, we are st...

how to fadein LI elements randomly? (jquery)

Hi I've got a set of <li> with a hover effect, what I want is when the page loads ALL the <li> elements fade-in randomly. I don't want to shuffle them...they should keep their ordering intact meaning 1,2,3,4,5. I just want to make them appear on the page randomly and stay there. Test page: http://humayunrehman.com/hovertest/ ...

Could random.randint(1,10) ever return 11?

When researching for this question and reading the sourcecode in random.py, I started wondering whether randrange and randint really behave as "advertised". I am very much inclined to believe so, but the way I read it, randrange is essentially implemented as start + int(random.random()*(stop-start)) (assuming integer values for start ...

Template problems: No matching function for call

I'm trying to create a template class, and when I define a non-member template function, I get the "No matching function for call to randvec()" error. I have a template class defined as: template <class T> class Vector { T x, y, z; public: //constructors Vector(); Vector(const T& x, const T& y, const T& z); Vector(const Vector& u); /...

Is C# Random Number Generator thread safe?

can anyone tell me if the C# Random.Next() method is thread safe? ...

Join a single row in one table to n random rows in another

Is it possible to make a join in SQL server that joins each row from table A to n random rows in another? For example, say I have a Customer table, a Product table and an Order table. I want to join each customer to 5 random products and insert these rows into the order table. (And each customer should be joined to 5 random rows of his o...

Random number in a loop

Hi all, having an issue generating random numbers in a loop. Can get around it by using Thread.Sleep but after a more elegant solution. for ... Random r = new Random(); string += r.Next(4); Will end up with 11111... 222... etc. Suggestions? ...

Maximal Length of List to Shuffle with Python random.shuffle?

I have a list which I shuffle with the Python built in shuffle function (random.shuffle) However, the Python reference states: Note that for even rather small len(x), the total number of permutations of x is larger than the period of most random number generators; this implies that most permutations of a long sequence can never be g...

Can Java's random function be zero?

Just out of curiosity, can Math.random() ever be zero? For example, if I were to have: while (true){ if (Math.random() == 0) return 1; } Would I ever actually get a return of one? There's also rounding error to consider because Math.random() returns a double. I ask because my CS professor stated that random() goes from 0 to 1 ...

Oracle aggregate function to return a random value for a group?

The standard SQL aggregate function max() will return the highest value in a group; min() will return the lowest. Is there an aggregate function in Oracle to return a random value from a group? Or some technique to achieve this? E.g., given the table foo: group_id value 1 1 1 5 1 9 2 2 2 4 2 8...

How to pull random rows from a database but ensure every row is selected before any are repeated?

I am doing a project on the blackberry. There are two XML databases, Full & Lite. In total there are 350 questions in Full and 20 questions in Lite. When a user takes the Full test, 50 questions are randomly asked from the full set of 350, chosen at random (for Lite it's 10 questions). As the user retakes the test, I want to ensure ever...

random permutation

I would like to genrate a random permutation as fast as possible. The problem: The knuth shuffle which is O(n) involves generating n random numbers. Since generating random numbers is quite expensive. I would like to find an O(n) function involving a fixed O(1) amount of random numbers. I realize that this question has been asked before...

Random array special

how make special random array. i have array(1=>35,2=>25,3=>40). how make possibility that array show special elements. Ex. If i want get 100 elements from array. it will be 35/100 +-10 - must bee 1 element, 25/100 +-10 = must be 2 element, 40/100 +-10 - must be 3 element. Elements must be random, but most elements +-10. i know its pos...