random

displaying random numbers

Hello I'm trying to design a code where one guess a number. I defined the range which number to display in my listbox. I started to write Random(1,10) but if I enter 11, it still writes in my listbox. How can I just write the number selected from my range, which is 1-10? I'm quite lost here. Any ideas? Thanks here is a part of my code...

Reassigning the values of a table PK randomly

Which is the easiest way to perform the following in MySQL 5.1? I have a table with a primary key as an integer, currently running from 1 to 220. The PK runs sequentially depending on the order in which the rows were written to the table. I want to be able to randomly reassign this primary key value, so that, for example, row 1 (with a...

How to random seed from memory usage?

In windows, I want to generate random number with seed: time + memory usage. I want to get the memory usage from physical memory sytem cache the one that appears in taskmgr. So, How to get physical memory system cache in c (windows and not .net )? The random seed may end up something like this: srand((unsigned int)(time(0)+ memSystemC...

Adjust algorithm for generating random strength values

A few days ago, you helped me to find out an algorithm for generating random strength values in an online game (thx especially John Rasch). function getRandomStrength($quality) { $rand = mt_rand()/mt_getrandmax(); $value = round(pow(M_E, ($rand - 1.033) / -0.45), 1); return $value; } This function generates values between ...

Diehard test only integers?

i want to test some "random" numbers in (0 1). i will test them with the diehard tests battery, but i dont know if it tests numbers in (0 1). so diehard test any kind of numbers, or it just test intergers? ...

Is it irrational to sanitize random character strings for curse words?

If you exposing randomly generated strings or strings with data encoded in them (Product keys). Is it irrational to sanitize them for curse words to avoid the client possibly getting offended in the rare case an offensive word is generated. Anybody ever have a customer get offended by a randomly generated curse word? Anybody out there ...

Is it correct to use JavaScript Array.sort() method for shuffling?

I was helping somebody out with his JavaScript code and my eyes were caught by a section that looked like that: function randOrd(){ return (Math.round(Math.random())-0.5); } coords.sort(randOrd); alert(coords); My first though was: hey, this can't possibly work! But then I did some experimenting and found that it indeed at least see...

collecting numbers and printing them

so what I'm trying to accomplish is generating 100 random 0's and 1's add them all into one variable and then print it. What I have right now I don't know how to make work. If someone could explain what I'm doing wrong, I would be very grateful. randstring (void){ int i; int num; char buffer[101]; i=100; while(i>0, i...

Is this a good way to generate a string of random characters?

I found this snippet of code that generates a string of random characters: http://www.c-sharpcorner.com/UploadFile/mahesh/RandomNumber11232005010428AM/RandomNumber.aspx But is there a more elegant/faster/more reliable way to do this? This seems to rely on the fact that the numbers 26-91 are valid characters given the current encoding. ...

Shuffling a list of objects in python

I have a list of objects in python and I want to shuffle them. I thought I could use the random.shuffle method, but this seems to fail when the list is of objects. Is there a method for shuffling object or another way around this? import random class a: foo = "bar" a1 = a() a2 = a() b = [a1,a2] print random.shuffle(b) This will...

Issues with seeding a pseudo-random number generator more than once?

I've seen quite a few recommendations for not seeding pseudo-random number generators more than once per execution, but never accompanied by a thorough explanation. Of course, it is easy to see why the following (C/C++) example is not a good idea: int get_rand() { srand(time(NULL)); return rand(); } since calling get_rand several ...

How to get mysql random integer range?

I am trying to generate a random integer for each row I select between 1 and 60 as timer. SELECT downloads.date, products.*, (FLOOR(1 + RAND() * 60)) AS timer I have searched and keep coming up to this FLOOR function as how to select a random integer in a range. This is giving me a 1 for every row. What am I missing? I am on mysql ...

Why does MySQL Rand() hate me?

Here is a simplified query of something I am trying to do on a larger join query. It is still breaking on this small scale. I am trying to generate a random number for each row pulled back in the range of 1-60. I then want to order the returned rows by this random number. SELECT downloads . * , (FLOOR( 1 + ( RAND( ) *60 ) )) AS random...

RandomNumber method returns same number every time called

Hi There, I am trying to generate a different random number every time my RandomNumber method is called from within my for loop. Right now, it returns the same number every time. This is my RandomNumber method: private int RandomNumber(int min, int max) { Random random = new Random(); return random.Next(min, ma...

sed to replace random numbers

Hello, i need to let sed replace some url in alot of file each file has the following http://www.expample.com/file.php?id=xxxxxxx where xxxxx consist of random numbers , random depth in each file like file 1 _h**p://www.expample.com/file.php?id=xx file 2 _h**p://www.expample.com/file.php?id=xxxxxxxx etc thanks in advance ...

Best way to randomize a list of strings in Python

I receive as input a list of strings and need to return a list with these same strings but in randomized order. I must allow for duplicates - same string may appear once or more in the input and must appear the same number of times in the output. I see several "brute force" ways of doing that (using loops, god forbid), one of which I'm ...

What common algorithms are used for C's rand()?

I understand that the C specification does not give any specification about the specific implementation of rand(). What different algorithms are commonly used on different major platforms? How do they differ? ...

Comparison method for sorting that shuffles equal elements randomly

Here's a puzzle for you. I want to change the following comparison method, so that when two items are considered equal, they will be shuffled randomly. myList.Sort( (x, y) => x.Score.CompareTo(y.Score) ); I could imagine that this scenario would be useful when ordering search results if you didn't want to give preference to one resul...

How can I randomly sample the contents of a file?

I have a file with contents abc def high lmn ... ... There are more than 2 million lines in the files. I want to randomly sample lines from the files and output 50K lines. Any thoughts on how to approach this problem? I was thinking along the lines of Perl and its rand function (Or a handy shell command would be neat). Related (Poss...

PHP: Best random numbers

Hello! I heard that PHP's rand() function doesn't give good random numbers. So I started to use mt_rand() which is said to give better results. But how good are these results? Are there any methods to improve them again? My idea: <?php function rand_best($min, $max) { $generated = array(); for ($i = 0; $i < 100; $i++) { ...