random

How to generate random password with PHP?

Or is there a software to auto generate random passwords? ...

Fast random selection algorithm

Given an array of true/false values, what is the most efficient algorithm to select an index with a true value at random. A sketch simple algorithm is a <- the array c <- 0 for i in a: if a[i] is true: c++ e <- random number in (0, c-1) j <- 0 for i in e: while j is false: j++ return j Can anyone come up with a faster algor...

Uniform random (Monte-Carlo) distribution on unit sphere.

Hi! I need a clarification with algorithm generating random values for my pet ray-tracer. I emit rays from one point. And I have the problem with distribution of these rays: I need the distribution to be uniform, but it isn't... The problem I face now is that the distribution being uniform initially is not uniform after my distortions...

boost::random generate the same number every time

main .cpp #include "stdafx.h" #include "random_generator.h" int main ( int argc, char *argv[] ) { cout.setf(ios::fixed); base_generator_type base_generator; int max = pow(10, 2); distribution_type dist(1, max); boost::variate_generator<base_generator_type&, distribution_ty...

How to order data randomly

I have the following MySQL. I want to pull the data in random order. Could anyonet teach me how to do it please. $Q = $this->db->query('SELECT P.*, C.Name AS CatName FROM products AS P LEFT JOIN categories C ON C.id = P.category_id WHERE C.Name = "Front bottom" AND p.status = "active" ...

Basic image rotation with jQuery

I'd like to test banner (two css background images) and rotate them randomly on each page reload. Is it possible to achieve something like that without using any plugins? I just need to rotate two images, which is basically just swapping css classes randomly on the banner element, on each reload. Many thanks. ...

Generating sorted random ints without the sort?

Just been looking at a code golf question about generating a sorted list of 100 random integers. What popped into my head, however, was the idea that you could generate instead a list of positive deltas, and just keep adding them to a running total, thus: deltas: 1 3 2 7 2 ints: 1 4 6 13 15 In fact, you would use floats, then norm...

Returning items randomly from a collection

I've a method which returns a generic list collection(List) from the database. This collection has got order details i.e., Order Id, order name, product details etc. Also, method the method returns a collection having only the top 5 orders sorted by order date descending. My requirement is that each time the client calls this method, I...

ORDER BY RAND() alternative

I currently have a query that ends ORDER BY RAND(HOUR(NOW())) LIMIT 40 to get 40 random results. The list of results changes each hour. This kills the query cache, which is damaging performance. Can you suggest an alternative way of getting a random(ish) set of results that changes from time to time? It does not have to be every hour ...

How random is urandom?

In Linux, just how random is /dev/urandom/? Is it considered safe? Also is it possible to get a stream of 1's? ...

Cleaner PHP Random Text

Playing around with generating text randomly with each page refresh using php. Is there a cleaner way to approach this? Also, can this be done with jquery? <?php $random_text = array("Random Text 1", "Random Text 2", "Random Text 3", "Random Text 4", "Random Text 5"); srand...

How to call a C function from random places inside another function ?

Can anyone tell me how to insert a function call (say Yield() ) at random places inside a C function , so that each time the code is run , Yield() gets called from different parts of the code ? I am faced with such a requirement as I'm using 2 threads in a cooperative threading environment , where unless the running thread yields the pr...

PHP, MySQL - would results-array shuffle be quicker than "select... order by rand()"?

I've been reading a lot about the disadvantages of using "order by rand" so I don't need update on that. I was thinking, since I only need a limited amount of rows retrieved from the db to be randomized, maybe I should do: $r = $db->query("select * from table limit 500"); for($i;$i<500;$i++) $arr[$i]=mysqli_fetch_assoc($r); shuffle($arr...

MATLAB generate random numbers

Hi I am trying to generate random numbers in MATLAB with a random MEAN value. For example, if I use e = mean(rand(1000,1)) the answer for e will always be close to 0.5. What I want is for the value of e (mean) to be random, so that e can be 0.1, 0.2, 0.3, etc... Is it correct for me to use e = mean( unifrnd(0,1,[1000,1]) ) ? Thanks...

Python random and int to string question

Hi, I am using this line of code to generate a random list of integers: random.sample(range(2000), 100) With this code i know i wont have double value's with my result. Is their maybe a faster way to achieve the same results? Now i actually have to convert these int to string. Whats the fastest way to do this? Thanks ...

Trying to generate several digit intervals in one number (LUA)

Basically I have to use a random function that can return a number between 0 and 2^16-1. I am trying to make use of this and generate let's say, 6 intervals between 1 and 6 (thinking of dice poker). Basically use that one number that is randomly generated for me (I can specify range only) and preferably only have to call it once. Then t...

How to generate random values that don't keep giving me the same value in 'runs' of numbers?

Hi I coded this OneAtRandom() extension method: public static class GenericIListExtensions { public static T OneAtRandom<T>(this IList<T> list) { list.ThrowIfNull("list"); if (list.Count == 0) throw new ArgumentException("OneAtRandom() cannot be called on 'list' with 0 elements"); i...

Adding Randomly choosen class to html tag using jQuery

Hello Gurus! Whet I need to do is in my menu I would like to add one of the classes (listed below) with completely random order every time when function starts (page load) This is my HTML <div id="menu"> <ul> <li><a href="#">Home</a></li> <li><a href="#">About Us</a></li> <li><a href="#">Portfolio</a></li> ...

Better random algorithm?

I'm making a game in c++ and it involves filling tiles with random booleans (either yes or no) whether it is yes or no is decided by rand() % 1. It doesnt feel very random. I'm using srand with ctime at startup, but it seems like the same patterns are coming up. Are there any algorithms that will create very random numbers? Or any sugges...

Ghost requests in asp.net?

In an ASP.Net WAP, the home page /default.aspx is receiving periodic requests from I-know-not-where. Thinking this was BS when it was reported, I fired up my local copy of the site under Cassini and set a breakpoint on the home page's page_load() event. Sure enough, every few minutes the breakpoint is hit. Any suggestions? This is a pre...