random

Don't reshow seen posts in Rails

Hi, I'm currently developing an application whereby a user clicks a button and they're offered up a new page of content, and was wondering how I would go about hiding or skipping past those that the user has already interacted with (a separate table stores the post_id and user_id for each view). I currently use this code in the model fo...

How to generate random positive and negative numbers in java

I am trying to generate random integers over the range (-32768, 32767) of the primitive data type short. The java Random object only generates positive numbers. How would I go about randomly creating numbers on that interval? Thanks. ...

Generate random sport game result c++

I was required to write a program that generate random results of 10 sport games where 10 countries are involved, and display the medal tally based on the results. I was able to generate the games' result but have no idea how to sum up the results (i.e. the number of different medals earned by each country). Below is part of my code to...

Passing parameter back to Model to refine Random action

Hi, I'm creating an application that'll display a random picture based upon a defined letter in a word. Images are attached to a Pictures model (containing another "letter" field) using Paperclip, and will be iterated through in an each block. How would I go about passing the letter back from the each block to the model for random sele...

PHP - choose 3 different random values from an array

Hi. As title said : I have an array of 30 values and i need to extract from this array 3 different random values. How can do it? cheers ...

Randomise order of if-else execution in Python

This might sound like a strange question, but bear with me... I have a dictionary in Python with values like so: 'B': 23.6 'D': 0.6 'F': 35.9 'H': 35.9 I need to do an if-else with these values to do different things depending which one is > 30. The code I have at the moment is along the lines of: if angles['B'] > 30: # Do stuff e...

How reliable is the Random function in Delphi

I am writing a program which write statistical tests in Delphi (must be Delphi) and I've heard that the Random functionality is somewhat odd. You have to call randomize to randomize the seed of the random function when the program starts. I'm wondering if the random function (after calling randomize) is random enough for statistical t...

Using C++0x TR1 random in a class, for low overhead

Hello, I'm using VC 2010 and trying to keep the overhead and duplicated code of certain functions low, by placing the random definitions in the constructor of each class instance, then calling as necessary from there. What I have now, simplified, is: #include <random> #include <Windows.h> mt19937 eng(GetTickCount()); class Cycles { ...

selecting a random element of the power set.

For a problem that I'm working on right now, I would like a reasonably uniform random choice from the powerset of a given set. Unfortunately this runs right into statistics which is something that I've not studied at all (something that I need to correct now that I'm getting into real programming) so I wanted to run my solution past some...

use of D.Knuth pseudo-random generator

Hi all, I need to write a physical simulation software, and I need to use the pseudo-random generator written by D.Knuth, cause it best fits my needs. Though I know how to use it within a hard block of code (a mere #include "rng-double.c"), I can't quite understand how to include it in a modular program where it is needed both within t...

Generate random string from 4 to 8 characters in PHP

Hi guys!! I need to generate a string using PHP, it need to be unique and need to be from 4 to 8 characters (the value of a variable). I thought I can use crc32 hash but I can't decide how many characters, but sure it will be unique. In the other hand only create a "password generator" will generate duplicated string and checking the v...

Understanding "randomness"

I cant get my head around this, which is more random? rand() OR rand() * rand() I´m finding it a real brain teaser, could you help me out? Thanks in advance! EDIT: Intuitively I know that the Mathematical answer will be that they are equally random but I can't help but think that if you "run the random number algorithm" twice wh...

mysql query to select one specific row and another random row.

Hi all. I want to display two records. For eg select * FROM users WHERE user_id = 5. Now i want another row randomly selected from users table but with user_id != 5 Is it possible to do in a single query. I tried using union all but i dnt get two distinct rows. Thanks ...

different rand() results on Windows and Linux

Hello ! I've noticed, that standard rand() function gives different results on Windows and Linux. Ofcourse I've used the same seed number (1234). Here are several first results: WIN: 4068 213 12761 8758 LIN: 479142414 465566339 961126155 1057886067 My application requires that both platforms produce identical output. What are my optio...

Array wraparound with modulo of unsigned

I'm trying to implement a lagged Fibonacci pseudo-random number generator for integers up to some maximum. It maintains an array of values int values[SIZE] = { /* 55 seed values */ }; and uses the following function to return the next value unsigned lagfib() { static unsigned idx = 0; int r = values[idx]; /* The followin...

Complex mysql query, please help.

I have a table of banners. Banners are marked with size id and slot id(position on page) I need to pick 8 banners of one size, 1 for each slot between 11-18(slot id) and keep randomness each page view, so that each time banners were different if there any different for required slot. The only solution i have found is this: SELECT * FR...

Generate Random number between two number with one rare number..

Hi all, i can generate random number between two numbers in c using this.. arc4random()%(high-low+1)+low; then now my requirement is...i want to make a number rare....thats mean if high=5, low=1, and rare=3, than 3 will be appeared much rarely than 1,2,4 and 5... Thanks ...

How to get really random number?

Possible Duplicates: Understanding randomness Fastest implementation of a true random number generator in C# Hello. Function: Random rand = new Random(); rand.Next() It gives pseudo random numbers based on time in seconds. How to get really random numbers? I mean totally random not based on system time and some algorithm....

C# Produce a Random Number in a range

How do I go about producing random numbers within a range? ...

update table with random values

I have two tables, lets say Table1(Col1,Col2,Col3,Col4) and Table2(Col1). I want to update some cols in Table1. For each row in Table1 where Col1 ends with '001' (assume all values are at least length 4) I want to: 1.place a random number from the set (10,20,30,40,50,60,70,80,90) in Col2. 2.place a random 9 digit number in Col3. ...