FAQ Database Discussion Community
php,arrays,random
I have a array that i want to select two item as random, And two keys are selected between the key 2 and the key 8. $arr = array=(1,2,3,4,5,6,7,8,9,10,11,12); I can get two random item: $rand_keys = array_rand($arr, 2); $arr[$rand_keys[0]]; // one $arr[$rand_keys[0]]; // two In the above code, It...
java,arrays,random,combinations
I have to arrays with integers: int[] a={1,2,3,4,5}; int[] b={6,7}; I would like to generate an array, which contains pairs from the a and b arrays, in a random order, without duplicates. For example I would like to get the following result: c={(1,6),(2,7),(4,6),...} Thanks!...
swift,if-statement,random
Still a beginner with just playing around with some basic functions in swift. Can someone tell me what is wrong with this code? import UIKit var guessInt: Int var randomNum = arc4random_uniform(10) if Int(randomNum) == guessInt { println ("correct") } else { println; "no, the number is not. guess again"...
php,random
I have 2 php functions on a webpage, I would like to run one of those 2 functions randomly, I know how to do it with divs or html using php, but not how to run a php function randomly. I want to use php and not Javascripy here are...
javascript,arrays,random,javascript-objects
I have an array of objects (I am not so sure if that's the correct way to create it). Each of them have the same properties but different values. I want to access the properties of a random object in this array, but just one time - so when I...
random,brute-force,stochastic,sat-solvers,sat
right now I am writing about SAT-solving and I am stuck at a point. I am hoping that you can help me. I want to describe some methods to solve SAT-Problems. Right now I have three different ways: Bruteforce Random (naive) DPLL (with different heuristics) ? missing ? ... My...
python,random,mocking
Background I want to test my code which depends on random module. The problematic PR is https://github.com/Axelrod-Python/Axelrod/pull/202 and code is here https://github.com/Axelrod-Python/Axelrod/blob/master/axelrod/strategies/qlearner.py The problem Since random module produces pseudo-random numbers, I always set random.seed(X) to known value X. This works for consecutive test runs. However, Python 3 seems to give...
text,random,lua,corona
I'm have a problem because when I touch my button sometimes my text doe not appear and I do not understand what is wrong. Code: function randomText(event) display.remove(mmDis) local a = {"Cristiano ronaldo jest najlepszy!", "messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"} com = (a[math.random(1,#a)]) local mmDis =...
java,random
My question is does the code below generate a random number properly as in the last 20 tries I got 500 000 5 times which does not reflect the 2% chance of getting it at all... public static int randInt(int min, int max) { // NOTE: Usually this should be...
r,random
I'm trying to understand why the following 2 code snippets lead to different output and I'm hoping someone can enlighten me. The second version is marginally faster - which is my motivation since this all sits in a loop, but I need to know if it is equivalent and if...
ruby-on-rails,arrays,ruby,string,random
I have a multi-dimensional array: [ [:C], [:C, [:C]], [:C, [[:C]]], [:C, [:C, [:C]]], [:C, [:C, [:C, :C]]], [:C, [:C, [:C, [:C]]]], [:C, [:C, [:C, [:C, :C]]]], ] I need to translate it into a string like this: "C C(C) C((C)) C(C(C)) C(C(CC)) C(C(CC)) C(C(C(C)))" For clarity, here are the...
python,variables,python-3.x,random,introspection
I have a list of names, and I would like my program to randomly select one of those names. I tried using the following: import random def main(): Arkansas = 1 Manchuria = 2 Bengal = "3" Baja_California = 4 Tibet = 5 Indonesia = 6 Cascade_Range = 7 Hudson_Bay...
java,android,random,spawn
i have problem with Android. I'm trying make project that i draw circles on random position. After touch on this circle you will get score and circle will disapear. But i have problem that my object is spawn then disapear without touch and spawn i other location. Here is my...
python,random,random-seed
Seeding Python's built-in (pseudo) random number generator will allows us to get the same response each time we use that seed -- documentation here. And I've heard saving the internal state of the generator reduces the likelihood of repeating values from previous inputs. Is this necessary? That is, is getState()...
java,random,random-seed
I'd like to generate n random bytes from a given m-byte seed. The generated sequence has to be reproducible; for the same seed the same sequence has to be generated. n can be either higher or lower than m. The two following trivial approaches that are coming to my mind...
java,arrays,random
I am trying to write a program that prints a 2d array with random numbers ranging from 100-10000 and prints out the max number in the array,average,and min. The program will ask the user for the number of rows and column and print random numbers in that array. Here is...
python,arrays,random
In Python we can make a random array from 0 to 10 by doing: randarray = random.sample(range(0, 10), 10) My problem is that I want to create an array from 0 to 10, BUT in the first position I want to add a randomly generated number, and then append the...
r,random
I have this piece of script for R and I want to adjust it a little bit. Here's the script I have, mydata is an imported .csv file of n columns: library(orddom) R=6 delta = numeric (R) for (i in 1:R) {` a <- data.matrix(sample(mydata, 2, replace=FALSE)) drops <- c(colnames(a))...
r,random,random-seed
I have a dataset that consists of nearly 7 million observations and I want to take a random sample of the data to analyze just a subset. I know how to take a random sample of the data: index <- sample(7009728, 50000) flights <- flight[index, ] Is there a way...
text,random,sdk,corona
I`m have a problem because when i touch my button sometimes not appear my text... (Sorry for my English!) Code: function randomText(event) display.remove(mmDis) local a = {"Cristiano ronaldo jest najlepszy!","messi jest dobry!","lewandowski jest ok","diego lopez to bramkarz realu"} com = (a[math.random(1,#a)]) local mmDis = display.newText(tostring(com), display.contentWidth*0.57, display.contentHeight*0.7, display.contentWidth*0.9, display.contentHeight*0.8, "Impact",...
list,random,q,kdb,nul
I am having a random (Y) list with (X) elements (seed elements in 2nd dimension) where I want to reset values on a random factor (Z) that is between 0f and 1f. For numerical lists this code works fine q)seed:20 q){(0>z-(x#seed)?\:1f)*(x#seed)?\:y}[3;10;0.25] How can I extend that code to be running...
c#,arrays,algorithm,random,cycle
The following LINQPad code generates random sequence of unique integers from 0 to N and calculates the length of cycle for every integer starting from 0. In order to calculate cycle length for a given integer, it reads value from boxes array at the index equal to that integer, than...
c++,random,generator
I wrote a simple program (tried to implement the Linear congruential generator actually), but I'm not quite sure it works like it should. I wanted to generate 250 number from [0,1] using my generator. However, it seems that instead of random numbers, I get equal values .. How to improve...
java,android,loops,random
I am using Android Studio and I wanted to loop this every half a second "Random rand = new Random(); int value = rand.nextInt(10);" So anyway thanks for your time and if you can help that would be great. :) Sincerely, Igor EDIT Thanks everyone for the kind and helpful...
c++,c++11,random
In the code below, RandomCharSource is supposed to simply return a random character upon request. Its constructor is initializing an mt19937, uniform_int_distribution<int> and a random_device. However, when I instantiate my object, I get a segfault. When I create these random classes manually in the bar() function below, it works fine....
bash,random
I have a bash script on a headless Linux server that accepts a file name as parameter and displays the provided image fullscreen on a beamer. Users can upload images to a shared folder. I want a random picture of that folder to be chosen each few seconds and displayed....
vb.net,random,visual-studio-2013
I'm new to Visual studio so.. I'm stuck. I want to randomize between my numbers: 69, 119, 179. So when i press button1 it's gonna pick one of the 3 choices. And then show it in Textbox1. Just as simple as that. I found a randomize video on youtube that...
c++,random,std
I want to use std::rand() to generate a number between 0 and amountOfNumbers, but the generated number can't be the same number that was last generated. I wrote this function: void reroll() { int newRand; while (true) { newRand = std::rand() % (amountOfNumbers); if (newRand == lastNumber) { continue; }...
r,random,data.frame,seq
I have a data.frame which I want to generate random numbers each list by a sequence. I used sample function to create random numbers but even I created random numbers for list [[1]], for set [[2]] same numbers produced again. So, here how can I create different random numbers for...
variables,random,jmeter
I have 1st thread group that GETs some id's and writes it to the variable. This var has view like that "654564546,564564,56454,56456454,21231321,8972341,65423187". I need to pick up randomly one of the id and put it to the another variable. In jmeter 2.07 I used this code: import java.util.Random; String[] erroridcox...
python,numpy,random
I need to do a random choice with a given probability for selecting a tuple from a list. EDIT: The probabiliy for each tuple is in probabilit list I do not know forget the parameter replacement, by default is none The same problem using an array instead a list The...
java,random,collections
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; public class ShuffleList { public static void main(String[] args) { String [] file = {"1","2"}; long seed = 3; ArrayList<String> fileList = new ArrayList<String>(Arrays.asList(file)); for (int i=0; i<200; i++) { Collections.shuffle(fileList, new Random(seed)); seed = seed +1; System.out.println(seed + "," + fileList);...
java,android,random
I am trying to show a random fact and change the background color each time the fact changes. I do it using a random number on the MainActivity but as soon as I press the button to generate and show that random number the app crashes. Here is the link...
python,list,random
My class was recently introduced to lists and our task is to randomly obtain a name from the said list, This is the code i have generated import random Random1 = random.randint(0,7) Class_List = ['Noah','Simone','Ji Ho','Thanh','Nathanial','Soo','Mickel','Tuan','Thuy Linh'] print (ClassList[{}].format(Random1)) However i receive this error Traceback (most recent call last): File...
php,random
This question already has an answer here: PHP random string generator 35 answers I'm trying to create a random string with numbers and letters and I found this function and thought it would be good, but I don't know if it is the correct way to create a true...
java,random,floating-point
I found that Random#nextFloat returns a value between 0.0 and 1.0. How can I get a random float value such as -72.0F or 126.232F? I currently doing like this. float randomFloat() { final ThreadLocalRandom random = ThreadLocalRandom.current(); float value = random.nextFloat() * Float.MAX_VALUE; if (random.nextBoolean()) { value = 0 -...
c++,c++11,random,shuffle
I have a class Permutation that inherits from std::vector<int>. I created a constructor that makes the object filled with non-repeating numbers. Randomness is meant to be guaranteed by <random> stuff, so the declaration goes like this: /* Creates a random permutation of a given length * Input: n - length...
php,random
This question already has an answer here: Why the range of int is -32768 to 32767? [closed] 5 answers I realize in some programming languages, random number generators generate a default value of 0 to 32767 (for example, in php, rand(); will return a float between 0 and 32767)....
batch-file,random,ip,ping
I have made a program that creates random IPs and pings them to see if they exist. It records the output using '>' and '>>'. I want to check if the ping times out and if it does exclude it from the text document. This is my code so far:...
c,algorithm,random
In C, how do I get an array of n numbers (each 0x00-0xFF in my case), of which the sum is within a given range 0..k? The almost duplicate C++ multiple random numbers adding up to equal a certain number targets a specific sum, but in my case the sum...
java,android,button,random
Friends, I am a Civil Engineer. Now i am working now in Android Developing. I know Java and C# but i am mentally set my Programming knowledge is only editing like Reading and Understand. How to increase my skill like writing Programs Specially for C# and Java. Thank You. then...
matlab,random,distribution,gaussian,sampling
I would like to create a gaussian curve between two values (which is the end point of two different calculations). I am aware that i require a bit more background info, but i wish to play with the result. So let us assume what is not known, the values in...
php,arrays,random,tournament
If i have this: $players = array("A","B","C","D","E","F","G","H","I","J","L","M","N","O","P","Q"); How i populate a single tournament elimination like this for example: Matche 1: AxL Matche 2: CxJ Matche 3: HxQ . . . Matche 8: ExP 16 players = 8 Matches I try this and other codes too: <?php $players = array("A","B","C","D","E","F","G","H","I","J","L","M","N","O","P","Q"); shuffle...
c#,random
I have a lot of text files with values, although the lines in the text file should be partially scrambled. An example of a text file is as follows: (see the edit for an easier example) 0.00;1.2;3;2015-20-06 13:33:33 0.00;1.2;3;2015-20-06 13:33:34 0.00;1.2;3;2015-20-06 13:33:35 0.00;1.2;3;2015-20-06 13:33:36 [RAND] 0.00;1.2;3;2015-20-06 12:05:05 0.00;1.2;3;2015-20-06 12:05:22 0.00;1.2;3;2015-20-06...
javascript,jquery,random,height
Here is my loop: var i=0; while( i++ < 100) { $( "#container" ).append('<li id="li' + i + '" class="item image"></li>'); var y = Math.floor(Math.random() * 200) + 100; $('#li' + i).css({ height: y, }); } This somewhat does what I need it to do. It locates the #container element...
random,psychopy,experimental-design
I am using the PsychoPy Builder and have used the code only rudimentary. Now I'm having a problem for which I think coding is inevitable, but I have no idea how to do it and so far, I didn't find helpful answers in the net. I have an experiment with...
arrays,bash,random
I have a function that selects a random object form an array. I have wrapped the internal bash function RANDOM, and implemented my function like that: function rand() { echo $[ $RANDOM % $2 + $1 ]; } function rand_obj() { objs=([email protected]); index=$(rand 0 $#); echo ${objs[$index]} ; } It...
python,numpy,random,random-seed
I want to generate a random seed in a predictable way. I was hoping to do this seed = 12345 prng_0 = random.Random(seed) prng_1 = random.Random(prng_0.rand_int(0)) There, 0 is the lower bound, but it turns out I need to give it an upper bound as well. I don't want to...
python,python-3.x,random
I have a set of 9 elements and I want to write a program which prompts the user for an integer n, then displays n number of elements selected randomly from my set. This is what I tried: import random def main(): best_of = eval(input("How many maps do you want...
haskell,random
In Haskell, I'd like to generate a random list of Ints and use it throughout my program. My current solution causes the array to be created randomly each time I access/use it. How can I overcome this problem?...
python,random
I'm currently trying to pick a random text stored in a numbered variable like this source1 = '''First text''' source2 = '''Second text''' randomtext = source[randint(1,2)] liste_source = randomtext.rstrip('\n\r').split(" ") However, it returns me an error message saying that the source is not defined... I don't understand because the source1...
php,random,random-seed
Background: If you seed your prng, it will print out the same random sequence. So, if I tell you that I used the seed 123 and I got 1, 5, 2, 4. Then, you can use the seed 123 and get 1, 5, 2, 4. What I want to do...
python,string,python-2.7,random
This question already has an answer here: How to generate random numbers that are different? [duplicate] 3 answers I am trying to write a program in python 2.7 that has to choose more than one random variable and print it out. But the variable can't be the same as...
jquery,random
I'm trying to randomize this function i made, but i've only found a random TimeOut solution. I want the order to be random not the timeout. $(document).ready(function() { function boucle() { $('#test img').fadeTo(1000, 0); $('#test img').delay(1000).each(function(i) { $(this).delay((i++) * 1500).fadeTo(1500, 1); }); } boucle(); setInterval(boucle, 15000); }); I tried this...
matlab,matrix,random,4d
I have a 4D matrix with dimensions 7x4x24x10 (Lets call it main_mat). I want to get a matrix of size 7x4x24 (rand_mat) so that each element of this (rand_mat) matrix is actually a uniformly random draw from the main matrix (main_mat). I am sorry if I have not put the...
python,python-3.x,random
I'm trying to make a random NPC generator in Python--the last time I tried this, it was in PHP, and that went. . . strangely. What I'd like to be able to do with this is to call the defined variables within the string multiple times. I can do that...
python,list,random
I have a list of over million tuples and want a list of 100,000 tuples randomly sampled from that original list without replacement. I have read: How do I pick 2 random items from a Python set? but the solution provided (using random.sample while casting list to a set) does...
java,android,random
I have a quiz application what show few questions from the SQLite Db, it has 50 questions, but it must be show 5 questions in the game part and will be randomize these. I tired many times for the solution, but nothing :/ In the source code qid is the...
bash,shell,unix,random,passwords
I have following code </dev/urandom tr -dc '[email protected]#$%&_+=' | head -c 16 which is randomly generating password perfectly. I want two changes: It should only contain 1 special symbols that i have listed there It should choose random length of the password I tried with length = $(($RANDOM%8+9)) then putting...
jquery,random,tooltip,delay,show
I am developing this "logo colors". I need the tooltip to appear in a DIV where id is #show after I click (this is OK). But after hover the buttons the tooltip is appearing anywhere it wants. Visit my problem here: http://web-stranky.org/pro_dementa/ $(document).ready(function () { $( document ).tooltip( { content:...
c++,random,c++98,boost-random
I need a "random" number generator, which produces the same result for a given seed on Windows, Mac, Linux, iOS and Android. Now I tried std::rand and boost::random_int_generator with boost::mt19937 but sadly the result is different between Windows and Mac. Does anyone know of a (C++) implementation, that works reliably...
php,database,random,laravel-5,unique
I'm trying to generate a unique/random string in Laravel 5 and check it through my table to see if it exists. This is what I have, but it seems to be giving the error stated in the title: public static function generate() { $exists = true; while ($exists) { $code...
vb.net,linq,random
I'm trying to get one random row from each group of rows. I'm trying to use LINQ, but I'm not sure if that's the right approach. I'd like a Dictionary of Key/Name pairs. My table is as such: AnswerGroup AnswerKey AnswerName --------------------------------------------- 1 1 Yes 1 2 No 2 1...
arrays,swift,dictionary,random
Is it possible to return a dictionary this way? i guess it's just some syntax i got wrong. struct Dare { var theDare: [String: String, String: Bool;] = [ ["dare": "Dare1", "darePerson": true], ["dare": "Dare2", "darePerson": false], ["dare": "Dare3", "darePerson": false], ["dare": "Dare4", "darePerson": true], ["dare": "Dare5", "darePerson": false] ]...
java,c++,algorithm,random
For example, for the dimension d=2, it means that we could generate a random angle 0<=a<2*pi, and then we could just use (x_1,x_2)=(r*cos(a),r*sin(a)) as the random vector. However, for the dimension d>=3, we could not just generate an angle and use it to represent the vector. Then how could we...
arrays,perl,random
I need to know how can I fill the array in perl randomly. For example: I want declare an array containing 10 elements smaller than 60. Can someone explain me how can I do it or send me any guide? I would be so grateful.
random,fortran,fortran90
I think my code below it's not exactly give me the same random distribution. subroutine trig_random_value() implicit none integer :: t, z, y, x real(real64) :: theta, r real(real64), parameter :: PI=4.D0*DATAN(1.D0) integer, dimension(12) :: date_time integer, dimension(12) :: seed call date_and_time(values=date_time) call random_seed seed = date_time(6) * date_time(7) +...
c,random,syscall,libc
Is there a way to make that the entropy of /dev/urandom is and stay uninitialized? My goal is to simulate an initialized or simply uninitialize /dev/urandom. How can I do a such thing? edit: I see my question has been downvoted. I am sure the person who did has a...
c#,random,unity3d
I have a bunch of gameObjects that I am assigning unique ids to in the Start function. void Start() { UniqueID = String.Format("{0:X}", DateTime.Now.Ticks); } I thought this would work but every now and then I get duplicate ids. How can I make sure that they are always unique?...
ios,swift,dictionary,random,xcode6
I started to learn swift by trying to make a quiz game. But i'm stuck at trying to display random questions from an dictionary. The reason why i use a dictionary is because the quiz i'm working on is based on chemistry elements which has different symbols. So Based on...
javascript,arrays,button,random,onclick
I've been trying to create a button that will take a random name from an array, and display it on an html page. Been trying for a long while to get this to work, with no results. What gives? As well, if you know the answer, how could I create...
python,random
>>> import random >>> random.SystemRandom.randint(0, 10) Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> random.SystemRandom.randint(0, 10) TypeError: randint() missing 1 required positional argument: 'b' SystemRandom is supposed to give random numbers though os.urandom, randint works like normal randrange: >>> print(random.SystemRandom.randint.__doc__) Return random integer in range [a, b],...
random
Normally, you initialize some kind of random number generator object with a seed (usually, the time) at the start of the application and then keep it around and ask it for random numbers. This object is the state. I have an application that starts, generates one number, then exits. Since...
c#,linq,random
Can someone explain me why the following LINQ query throws an InvalidOperationException? (Don't say that the list has no elements,the value that I'm looking for always exists in the collection) class Program { static int lastNumber; static void Main() { int loopCount = 100; int minValue = 1; int maxValue...
c#,random,datatable
I'm trying to create an application which import an excel file and read the data from it and it returns n records randomly as winners according to how many winners the user want from that list. so i read the data from excel file and assign it to a datatable...
c#,arrays,random
I have the following code which generates two non-duplicates arrays of integers based on a ratio. The codes works perfectly but for a 4000 line file, this takes some time. //Train & Test numbers int train = (int)(((double)Settings.Default.TrainingRatio / 100) * inputLines.Count()); int test = inputLines.Count() - train; //Train &...
python,matrix,random,permutation,shuffle
I would like to make a matrix whose lines are different permutations of the following vector= [1,2,3,4,5,10,10,10,10,10] I tried to use the random.shuffle function, but it seems that everytime I use that, It redefines all objects to which it is assigned. For example, I have tried the following: vec=[1,2,3,4,5] for...
c++,boost,random,normal-distribution
I'm trying to generate random numbers from normal distribution using boost's multiprecision. I can generate random numbers from uniform distributions, but when I tried to generate from standard normal, it reports an error. Here is the code: (follows from Examples from boost, change mpz_int to cpp_int, and mpf_float_50 to cpp_dec_float_50)...
c++,random,dev-c++
This question already has an answer here: srand() — why call it only once? 4 answers I am writing a program to simulate Knight's tour randomly. (See wikipedia for what it means: http://en.wikipedia.org/wiki/Knight%27s_tour) First, I create a chess object, which is basically just a 8*8 array with numbers to...
arrays,swift,dictionary,random
I have the following piece of code: struct Dare { var theDare: [[String: AnyObject]] = [ ["dare": "Dare1", "darePerson": true], ["dare": "Dare2", "darePerson": false], ["dare": "Dare3", "darePerson": false], ["dare": "Dare4", "darePerson": true], ["dare": "Dare5", "darePerson": false] ] func randomDare() -> Dictionary<String, AnyObject> { return theDare[Int(arc4random_uniform(UInt32(theDare.count)))] } } How can i...
javascript,random,numbers,type-conversion
I have a random number generator function that returns a random number. It looks like the problem is that sometimes it returns only one decimal place the, tenths place(i think it's called). I always want it to output a number with 2 decimal places (some times i would get 10.5...
batch-file,random
I am trying to make a random string in batch, and I have no idea what to do. I have called a random string of numbers with the %random% function, but I have no idea how to permanently replace certain characters in my variable: @echo off set subkey1=%random%%random%%random%%random%%random%%random% set subkey2=%random%%random%%random%%random%%random%%random%...
oracle,random,plsql,rowid
I'm trying to create a random ROWID for testing purposes. I know it's not the way to go, but since I have no data (yet) I just need to guarantee when inserting the "value" of the ROWID (using ROWIDTOCHAR function) I have a different string everytime. I've been reading DBMS_ROWID...
c++,c++11,random,double,double-precision
From the C++11 header , I was wondering if a std::uniform_real_distribution<double> object can spit out a double that's greater than 0.99999999999999994? If so, multiplying this value by 2 would equal 2. Example: std::default_random_engine engine; std::uniform_real_distribution<double> dist(0,1); double num = dist(engine); if (num > 0.99999999999999994) num = 0.99999999999999994; int test1 =...
c++,arrays,string,qt,random
In my small Qt application, I want to pick a random string out of an array after I clicked on a button. I've read many threads but nothing works for me. So in my slot there's an array with several strings in it. I also implemented <string>, <time.h> and srand....
python,loops,random,while-loop
I have written code that should draw two different cards. However, I am not sure how I should end the while statement. Should I use break or continue? The while statement is there to make sure you don't draw two of the same cards. import random card_values = ["the Ace",...
php,random,unique
How do I generate random 12 character char for URL of a page for the record in the database like how youtube does it with 11 characters https://www.youtube.com/watch?v=kDjirnJcanw I want it to be unique for each entry in the database and consist of letters of upper and lower case, numbers...
java,string,random,char,swap
I am supposed to write a method that scrambles a word, switching two letters in a word that is not the first or last character. I've initialized i and j as random integers between positions 1 and str.length() -1. Is there a reason why this loop would not print the...
c++,random
I wrote a small code to make sure that I can get random numbers from a really wide range, ex. [0, 10^36) because I am going to use these wide ranges later. My code is as follows: #include <iostream> #include <cmath> #include <random> #include <chrono> int main() { unsigned seed...
arrays,matlab,random
I want to generate a random binary sequence with a ratio of 50%, that is, the same amounts of 0s and 1s. This is what I have so far: length_sequence = 1000; ratio = 0.5; A = logical(randi([0 1],length_sequence,1)); The only problem is that I dont know how to set...
function,python-3.x,random,dice
I thought I'd finally worked out all the kinks in the dice rolling code I wrote for practice, but then apparently I forgot to save my work last night, and when I rewrote it this afternoon, the random.randint function didn't seem to be returning any numbers other than 1's and...
javascript,jquery,html,css,random
Hi_I’m trying to make a random number appear inside an img src= address in a div, so that a random image is generated every time the div is loaded. I have 10 images and their directory addresses are: "pictures/number1.jpg" "pictures/number2.jpg" "pictures/number3.jpg" ................ "pictures/number10.jpg" I’m able select one of these at...
c,arrays,random,struct,arduino
Im trying to output a random element from an array of structs on my Arduino. The struct looks like this struct questionStructure { char question[7]; int answer; }; I call a method in my loop that holds a bunch of questions with answers and a random question is then supposed...
python,random,scipy,sparse-matrix
I need to generate a sparse random matrix in Python with all values in the range [-1,1] with uniform distribution. What is the most efficient way to do this? I have a basic sparse random matrix: from scipy import sparse from numpy.random import RandomState p = sparse.rand(10, 10, 0.1, random_state=RandomState(1))...
javascript,image,random
i've been playing with jason brown's let it snow plug-in. his code only accommodates for a single custom image, and i've been trying to figure out how to change the code so it accommodates multiple custom images within a random range. !function($){ var defaults = { speed: 0, interaction: true,...
java,arrays,for-loop,random
I want to fill tab[110] array with random bits (so 1 and 0). Don't know how to fill with values 1-110, but not 0-109. My for-loop: for (int i = 0; i<tab.length; i++) { Random r = new Random(); tab[i] = r.nextInt(2); if (i%25==0) { System.out.println(""); } System.out.print(tab[i]+"("+i+")"+", "); }...
python,loops,numpy,random,normal-distribution
I have a file with 44,586 lines of data. It is read in using pylab: data = pl.loadtxt("20100101.txt") density = data[:,0] I need to run something like... densities = np.random.normal(density, 30, 1) np.savetxt('1.txt', np.vstack((densities.ravel())).T) ...and create a new file named 1.txt which has all 44,586 lines of my data randomised...
vb.net,visual-studio-2010,random,numbers,64bit
I am using the 64-bit verison of the Mersenne Twister, specifically the version: A C-program for MT19937-64 (2004/9/29 version). Coded by Takuji Nishimura and Makoto Matsumoto. and am receiving an integer overflow when compiling into the Release but don't get the exception during run-time in Debug. I have integer overflow...
arrays,algorithm,random,insert,time-complexity
So I had to insert N elements in random order into a size-N array, but I am not sure about the time complexity of the program the program is basically: for (i = 0 -> n-1){ index = random (0, n); (n is exclusive) while (array[index] != null) index =...
python,python-2.7,random
I am working on importing random in Python 2.7. I would like for this code to generate two random cards. The current code does not generate random cards. If I request cards (9,11) the code generates cards (9,J) totaling to 19. There is nothing random about the output. def blackjack(A,B):...