random

How to generate a random String in Java

Hi everyone, I have an object called Student, and it has studentName, studentId, studentAddress, etc. For the studentId, i have to generate random string consist of seven numeric charaters, eg. studentId = getRandomId(); studentId = "1234567" <-- from the random generator. and i have to make sure that there is no duplicate id. than...

How can I randomly execute code 33% of the time in PHP?

I'm not so sure how to write this: I want to generate a random number from 0 to 2, then write an if statement which executes specific code only 33% of the time. This is what I tried to do: if (rand(0, 3)=="2") { echo "Success" }; Thank you very much! ...

MySQL ORDER BY rand(), name ASC

I would like to take a database of say, 1000 users and select 20 random ones (ORDER BY rand(),LIMIT 20) then order the resulting set by the names. I came up with the following query which is not working like I hoped. SELECT * FROM users WHERE 1 ORDER BY rand(), name ASC LIMIT 20 ...

Repeating random variables in VBA

How can I use randomize and rnd to get a repeating list of random variables? By repeating list, I mean if you run a loop to get 10 random numbers, each random number in the list will be unique. In addition, if you were to run this sequence again, you would get the same 10 random numbers as before. ...

problem with random function in python

how can i using random function (in python) to choice a string from a txt list ? thanks a lot ...

Arbitrary-precision random numbers in C: generation for Monte Carlo simulation without atmospheric noise

I know that there are other questions similar to this one, however the following question pertains to arbitrary-precision random number generation in C for use in Monte Carlo simulation. How can we generate good quality arbitrary-precision random numbers in C, when atmospheric noise isn't always available, without relying on disk i/o or...

Where does that randomness come from ?

I'm working on a data mining research project and use code from a big svn. Apparently one of the methods I use from that svn uses randomness somewhere without asking for a seed, which makes 2 calls to my program return different results. That's annoying for what I want to do, so I'm trying to locate that "uncontrolled" randomness. Sinc...

Grab a random number of bytes from a file with bash?

I have a file of 256MB. I'd like to retrieve a random amount of data from this file and copy it to another file. Is there a way to do this in bash or some other way? G-Man Edit: choose a random number between 1 and 256 then copy that number of mb from one file to another. ...

SQL Randomization on Daily Basis

Hi, I have an SQL listing shops, but i would like to random the results on a daily basis. For example today I list bat 2, 6, 9 etc and tomorrow, 6,1,7,9 etc Is there a way to implement this? ...

Randomize files output in folder

Hello Stackoverflow. How do I randomize the order of the files I get out of: string[] files = Directory.GetFiles("folder"); Thank you! :-) ...

Silverlight System.Random sequencing cross platform

Hi Guys, I need to know the effect of different platforms on the System.Random object (Silverlight). Is the sequence created the same on Mac, PC and across 32 / 64 bit? Regards Tris ...

Random in 2 cycle, do I need to reinitialize?

I have this code: Random r = new Random(); while (mStack[step].hasNext()) { int rand = r.nextInt(length); for (int i = rand; i < length+rand; i++) { //use of i and rand } } and all this in a recursive call. Will this seed a new Random for each while iteration, different for each recursive call? Or I have to use...

Random problem connecting to MySQL

Environment: RHEL 5 servers, MySQL 5.1.43, PHP 5.1.6 (using MySQLi). Currently only available within our internal VPN network. Servers ServerA: Webserver ServerB/C/D: Database server (1 master 2 slaves) The error (on ServerA) [Tue May 25 11:12:17 2010] [error] [client CLIENTIP] PHP Warning: mysqli::real_connect() [function.mysqli-real...

Interesting task using random numbers only

Given any number of the random real numbers from the interval [0,1] is there exist any method to construct a floating point number with zero fractional part? Your algorithm can use only random() function calls and no variables or constants. No constants and variables are allowed, no type casting is allowed. You can use for/while, if/el...

Generating different randoms valid for a day on different independent devices?

Let me describe the system. There are several mobile devices, each independent from each other, and they are generating content for the same record id. I want to avoid generating the same content for the same record on different devices, for this I though I would use a random and make it so too cluster the content pool based on these ran...

How can you generate a JFrame in a Random Location?

As in wen you run any output in a frame, every time you run the program it pops on a different position on the screen? ...

Order By Rand by Time (HQL)

Hi all, I'm developing a web application using asp.net Mvc 2 and NHibernate, and I'm paging data (products in a category) in my page, but this data are random, so, I'm using a HQL statement link this: string hql = "from Product p where p.Category.Id=:IdCategory order by rand()"; It's working fine, but when I page, sometimes the same p...

Select random line in SQL database

Hi, I would like to select a random line in my database. I saw this solution on a website: SELECT column FROM table ORDER BY RAND() LIMIT 1 This SQL query run but someone said me that it was a non performant query. Is there another solution ? Thx ...

Parallel loops and Random produce odd results

I just started playing with the Task Parallel Library, and ran into interesting issues; I have a general idea of what is going on, but would like to hear comments from people more competent than me to help understand what is happening. My apologies for the somewhat lengthy code. I started with a non-parallel simulation of a random wal...

Linq to NHibernate, Order by Rand() ?

Hi everybody, I'm using Linq To Nhibernate, and with a HQL statement I can do something like this: string hql = "from Entity e order by rand()"; Andi t will be ordered so random, and I'd link to know How can I do the same statement with Linq to Nhibernate ? I try this: var result = from e in Session.Linq<Entity> orderb...