Ruby - return an array in random order
What is the easiest way to return an array in random order in Ruby? Anything that is nice and short that can be used in an IRB session like [1,2,3,4,5].random() # or random_sort([1,2,3,4,5]) ...
What is the easiest way to return an array in random order in Ruby? Anything that is nice and short that can be used in an IRB session like [1,2,3,4,5].random() # or random_sort([1,2,3,4,5]) ...
Hello friends I am trying to put together an app that has a set of text that can be randomized when the user presses the button to flip the page. Basically, pressing the button does two things; flip the page and changes the text to a randomly included phrase. I am trying to implement this by having the page curl into the same XIB file ...
I know that to (funcall (car (nth (random (length color-themes)) color-themes))) gives me a random color theme on every Emacs startup; but I hardly restart Emacs. How do I cycle between random color themes, say, every hour? ...
I have a function that returns a random number from 1-10. When I use it in my other function it works once, but then it starts having an error that it's not a function. This isn't the exact code, just an example code that's similar. It produces an error saying "TypeError: Property 'ran' of object [object DOMWindow] is not a function" Why...
I want to know if there is a much cleaner way of doing this. Basically, I want to pick a random element from an array of variable length. Normally, I would do it like this: myArray = ["stuff", "widget", "ruby", "goodies", "java", "emerald", "etc" ] item = myArray[rand(myarray.length)] Is there something that is more readable / simple...
hey, i wanna ask if i have a list of words let say 'tiger, lion, elephant, zebra, horse, camel, deer, crocodile, rabbit, cat' haw can i generate 5 words out of the list randomly in c programming? for example: tiger, zebra, cat, deer, horse or crocodile, rabbit, camel, zebra, elephant ect thank you in advance :D Edit: #include <st...
Suppose I want to randomly select a number n between 0 and 30, where the distribution is arbitrary, and not uniform. Each number has a corresponding weight P(n): P(0) = 5, P(1) = 1, P(2) = 30, P(3) = 25, and so on and so forth. How do I do a random selection from this set, such that the probability of selecting a number is proportional t...
Setting: A pseudo-random pattern has to be generated. There are several ways / or algorithms availible to create different content. All algorithms will generate a list of chars (but could be anything else)... the important part is, that all of them return the same type of values, and need the same type of input arguments. It has to be p...
Hi all, I need to get 1-2 rows from query result retrived with SQL select on indexed columns without getting the whole record set. For example I will retrieve 10 000 records using query SELECT * FROM table WHERE field 1>1 AND field1 < 10 but I need only 1 random row from this query regarding to highload of my database. I can use ...
Hi all! I have a list of 55 (or any number but 55 at the moment) questions in my iPhone app. I have written it at the moment so it goes through the questions from 1 to 55 in number order. However, I would like to make this order random (or pseudo-random anyway). I can do it programatically by generating a random number to pick one of...
I quite like being able to generate the same set of pseudo-random data repeatedly, especially with tweaking experimental code. Through observation I would say that rand() seems to give the same sequence of numbers each time*. Is it guaranteed to do this for repeated executions on the same machine / for different machines / for different...
Hi, Starting with an array with 10K values. I want to randomly get 1000 values from it and put them into another array. Right now, I am using a for loop to get the values, but I want to pick 1000 values and not have to loop 1000 times. The array_slice function works, but it doesn't give random values. What is the correct (most effi...
Say we have an array like this with 1 being two values and 2 being two values and 3, etc $language = array ( "1"=>array ( "Hola", "Spanish" ), "2"=>array ( "Fáilte", "Irish" ), "3"=>array ( "Yasou", "Greek" ) ); How would I randomly select ONLY 1 of 3 arrays an...
Hello, I would like to draw a random number from the interval 1,49 but I would like to add a number as an exception ( let's say 44 ) , I cannot use round(rand(1,49)) .So I decided to make an array of 49 numbers ( 1-49) , unset[$aray[44]] and apply array_rand Now I want to draw a number from the interval [$left,49] , how can I do that u...
I hope I can explain this well, if I don't I'll try again. I want to generate an array of 5 random numbers that all add up to 10 but whose allocation are chosen on an interval of [0,2n/m]. I'm using numpy. The code I have so far looks like this: import numpy as np n=10 m=5 #interval that numbers are generated on randNumbers= np.rand...
Hi, For an ecommerce site I want to generate a random coupon code that looks better than a randomly generated value. It should be a readable coupon-code, all in uppercase with no special characters, only letters (A-Z) and numbers (0-9). Since people might be reading this out / printing it elsewhere, we need to make this a simple-to-com...
I've written some code to generate a sequence of random characters, but it does not: byte[] sbytes = { 1, 0, 1, 0, 1 }; String sstring; System.Random r = new System.Random(); r.NextBytes(sbytes); sstring = Convert.ToBase64String(sbytes); sstring = Path.GetRandomFileName(); sstri...
How can I make a random number between something like 0.1 to 0.9 ? randint only work for integer numbers =/ Thank you ...
I haven't been able to find a very good way of getting 10 random records out of a sqlite database. Seen a few examples that work with mysql, but they don't seem to work well with sqlite even though I am trying to us Random() instead of rand(). I have tried to get random numbers and then get the records by id, but for some reason I am ge...
hi anyone know about how to use Random wallpaperid between limit IDs using RAND() php msql i use this but its RAND() whole database $sql_wallpaper = "SELECT * FROM wallpaper WHERE RAND()>0.9 ORDER BY RAND() LIMIT 0,5"; $res_wallpaper = mysql_query($sql_wallpaper); reply please ...