random

How do I test the quality of an encryption algorithm?

I want to test an encryption algorithm for strength. It doesn't have to be strong, it just has to resist accidental cracking and say, a determined hacker with 10-hours to waste. (I wrote the crypto algorithm. Yes, I know that this is generally a bad idea but I think that I have good reason.) What kind of tests should I do? So far I'...

What is the most random function in C++?

I've used #include<stdlib> #include<time> using namespace std; srand((unsigned)time(0)); int n=(rand()>>8)%4; but what other random functions are there, or what other function could be used as random number generators? EDIT: I don't really have a particular reason for asking this question, I just wanted to know if C++ had any other ...

How to generate a universe?

If I wanted to generate a universe/galaxy like that of Elite or Spore, what would be some good programming reference materials and algorithms to take into account? ...

SQL Query Help: select random employee of the month

Could any one show me how to get record from this statement Select random employee which is not an employee of the month in the last x months Table Employee ID EmployeeName Table EmployeeOfTheMonth ID EmployeeID MonthStartedDate MonthEndedDate Thank you very much ...

python random.random() causes "'module' object is not callable" when used in custom template tag

If I start python from the command line and type: import random print "Random: " + str(random.random()) It prints me a random number (Expected, excellent). If I include the above-two lines in my django application's models.py and start my django app with runserver I get the output on the command line showing me a random number (Grea...

Random Number Generator in CUDA

Hey people I've struggled with this all day, I am trying to get a random number generator for threads in my CUDA code. I have looked through all forums and yes this topic comes up a fair bit but I've spent hours trying to unravel all sorts of codes to no avail. If anyone knows of a simple method, probably a device kernel that can be c...

way to initialize a javabean to random values

I was looking for some utility class/code that would take a java bean and initialize all its values to random values. It could be done via reflection as some libraries already create the toString() or equals() methods. Is is useful while developing the UI to have some data for example. Other possible nice to haves: recursively initia...

Database-Generated Human-Friendly Codes

I'd like to create some human-friendly codes to identify my objects. I'm thinking about using the following rules: 6-digit random number the first character is not zero each code has an edit distance value of 2 or greater* from every other such code maybe a checksum too I'd like my MS SQL database to enforce that the codes I use are...

Splitting Probabilities

I've the following code in PHP which works fine (returns more or less 10 results each time it runs): function GetAboutTenRandomNumbers() { $result = array(); for ($i = 0; $i < 240; $i++) { if (Chance(10, 240) === true) { $result[] = $i; } } echo '<pre>'; print_r($result); echo '</pre>';...

Implementing shuffle on the celestial jukebox

How would one implement shuffle for the "Celestial Jukebox"? More precisely, at each time t, return an uniform random number between 0..n(t), such that there are no repeats in the entire sequence, with n() increasing over time. For the concrete example, assume a flat-rate music service which allows playing any song in the catalog by ...

quickest way to generate random bits

What would be the fastest way to generate a large number of (pseudo-)random bits. Each bit must be independent and be zero or one with equal probability. I could obviously do some variation on randbit=rand()%2; but I feel like there should be a faster way, generating several random bits from each call to the random number generato...

Efficient algorithm to randomly select items with frequency

Given an array of n word-frequency pairs: [ (w0, f0), (w1, f1), ..., (wn-1, fn-1) ] where wi is a word, fi is an integer frequencey, and the sum of the frequencies fi = m, I want to use a pseudo-random number generator (pRNG) to select p words wj0, wj1, ..., wjp-1 such that the probability of selecting any word is proportional to its ...

VS rand() problem with pthread-win32

I come into a strange problem in pthread programming I've compiled the following code in vs2005 with pthread-w32 #include <cstdio> #include <cstdlib> #include <ctime> #include <pthread.h> #include <windows.h> pthread_mutex_t lock; void* thread1(void *) { int r1; while(true) { pthread_mutex_lock(&lock); // rand is maybe a CS ...

Python list of objects with random attributes

(Edit: randrange is just random.randrange, I didn't write my own RNG) I'm trying to create a list of instances of a class I defined. Here's the entire class (by request): from random import randrange class Poly: points = [0] * 8 fill = 'red' alpha = 1.0 def __init__(self, width=100, height=100): for i in ran...

Do you have a better idea to simulate coin flip?

Right now i have return 'Heads' if Math.random() < 0.5 Is there a better way to do this? Thanks edit: please ignore the return value and "better" means exact 50-50 probability. ...

How to run a script at random intervals

Hi I want to write a batch job in c# that runs a task at a random(ish) interval e.g. every hour +/- 20 mins and if no update is needed, then to wait x2 the last time before running again. What is the best method to do this? ...

random values from db in c#

How can I retrive random random ItemIDs from the list of existing ItemIDs in ItemID column intge db, given below is the sqlcommand I've used. (SqlCommand RetrieveComm =new SqlCommand("SELECT * FROM item_k WHERE ItemID='" +intGetRequest+ "'", searchCon)) thanks, ...

Paging on a Random Items Data Set

I have to generate a list of items on a website which are random for the session of the user for that particular list of items. I am going to add a link to demonstrate the problem. WebSite Link Scenario: When a user comes in and clicks on the link, the items on the page should be randomized. As the user clicks on page two, three on...

Generating random couples in C#

I have a table in my DB with a list of people. I need to create a list of random buddies every day. The idea is that every day every person is paired with a differenct random person for that day. Since the table may get very large I was wondering what would be the best way to do such a thing? I have thought of 2 ideas but I am not so ...

Generate random player strengths in a pyramid structure (PHP)

Hello! For an online game (MMORPG) I want to create characters (players) with random strength values. The stronger the characters are, the less should exist of this sort. Example: 12,000 strength 1 players 10,500 strength 2 players 8,500 strength 3 players 6,000 strength 4 players 3,000 strength 5 players Actually, I need floating,...