Search Results

Search found 12705 results on 509 pages for 'random sample'.

Page 6/509 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • random() in python

    - by Arkapravo
    In python the function random() generates a random float uniformly in the semi-open range [0.0, 1.0). In principle can it ever generate 0.0 (i.e. zero) and 1.0 (i.e. unity)? What is the scenario in practicality?

    Read the article

  • Random position without overlapping

    - by Hwang
    How to stop MCs from overlapping each other? private function loadWishes():void { for (i; i } } private function checkOverlap(wishB:MovieClip) { wishB.x=Math.random()*stage.stageWidth; wishB.y=Math.random()*stage.stageHeight; for (var i:uint=0; i This doesn't seems to be working cause the amount of it checking whether MC is overlapping is about the amount of MC on stage. how to make it keep checking till everything's fine?

    Read the article

  • How would I create a random number?

    - by Elliot Bonneville
    How would I create a random number using C++? I've heard that one should use the time as a seed, but I'm not sure how to do that with the correct syntax. How would I do this? One more thing - how would I limit the random number to a particular range? I'm simulating a dice roll and getting numbers in the millions...

    Read the article

  • how to generate a random String? in java

    - by chandra wibowo
    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. thanks in advance

    Read the article

  • True random number generator

    - by goldenmean
    Sorry for this not being a "real" question, but Sometime back i remember seeing a post here about randomizing a randomizer randomly to generate truly random numbers, not just pseudo random. I dont see it if i search for it. Does anybody know about that article?

    Read the article

  • Interesting task using random numbers only

    - by psihodelia
    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 decimal 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/else or any other programming language operands.

    Read the article

  • Implementation of java.lang.Random in PHP and C

    - by justinhj
    I'm looking for a random number generator that I can run in PHP, C and Java that will always return the same sequence of numbers for a given seed. Here's the Java implementation I would use: java.util.random source Whilst this would be fairly straightforward to port to C and PHP, there is potentially a lot of work to get all the edge cases correct and handle differences in number representation. I'd be extremely happy to just copy and paste a fully tested version should it exist.

    Read the article

  • Generate a random filename in unix shell

    - by R S
    Hello, I would like to generate a random filename in unix shell (say tcshell). The filename should consist of random 32 hex letters, e.g.: c7fdfc8f409c548a10a0a89a791417c5 (to which I will add whatever is neccesary). The point is being able to do it only in shell without resorting to a program.

    Read the article

  • Generate 3 random number that sum to 1 in R

    - by user1034797
    I am hoping to create 3 (non-negative) quasi-random numbers that sum to one, and repeat over and over. Basically I am trying to partition something into three random parts over many trials. While I am aware of a= runif(3,0,1) I was thinking that I could use 1-a as the max in the next run if, but it seems messy. But these of course don't sum to one. Any thoughts, oh wise stackoverflow-ers?

    Read the article

  • Using boost::random as the RNG for std::random_shuffle

    - by Greg Rogers
    I have a program that uses the mt19937 random number generator from boost::random. I need to do a random_shuffle and want the random numbers generated for this to be from this shared state so that they can be deterministic with respect to the mersenne twister's previously generated numbers. I tried something like this: void foo(std::vector<unsigned> &vec, boost::mt19937 &state) { struct bar { boost::mt19937 &_state; unsigned operator()(unsigned i) { boost::uniform_int<> rng(0, i - 1); return rng(_state); } bar(boost::mt19937 &state) : _state(state) {} } rand(state); std::random_shuffle(vec.begin(), vec.end(), rand); } But i get a template error calling random_shuffle with rand. However this works: unsigned bar(unsigned i) { boost::mt19937 no_state; boost::uniform_int<> rng(0, i - 1); return rng(no_state); } void foo(std::vector<unsigned> &vec, boost::mt19937 &state) { std::random_shuffle(vec.begin(), vec.end(), bar); } Probably because it is an actual function call. But obviously this doesn't keep the state from the original mersenne twister. What gives? Is there any way to do what I'm trying to do without global variables?

    Read the article

  • Hausman Test, Fixed/random effects in SAS?

    - by John
    Hey guys, I'm trying to do a fixed effecs OLS regression, a random effects OLS Regression and a Hausman test to back up my choice for one of those models. Alas, there does not seem to be a lot of information of what the code looks like when you want to do this. I found for the Hausman test that proc model data=one out=fiml2; endogenous y1 y2; y1 = py2 * y2 + px1 * x1 + interc; y2 = py1* y1 + pz1 * z1 + d2; fit y1 y2 / ols 2sls hausman; instruments x1 z1; run; you do something like this. However, I do not have the equations in the middle, which i assume to be the fixed and random effects models? On an other site I found that PROC TSCSREG automatically displays the Hausman test, unfortunately this does not work either. When I type PROC TSCSREG data = clean; data does not become blue meaning SAS does not recognize this as a type of data input? proc tscsreg data = clean; var nof capm_erm sigma cv fvyrgro meanest tvol bmratio size ab; run; I tried this but obviously doesn't work since it does not recognize the data input, I've been searching but I can't seem to find a proper example of how the code of an hausman test looks like. On the SAS site I neither find the code one has to use to perform a fixed/random effects model. My data has 1784 observations, 578 different firms (cross section?) and spans over a 2001-2006 period in months. Any help?

    Read the article

  • random data using php & mysql

    - by Prakash
    I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT NULL auto_increment, title text NULL, tags text NULL, PRIMARY KEY (id) ); data on field tags is stored as a comma separated text like html,php,mysql,website,html etc... now I need create an array that contains around 50 randomly selected tags from random records. currently I am using rand() to select 15 random mysql data from database and then holding all the tags from 15 records in an array. Then I am using array_rand() for randomizing the array and selecting only 50 random records. $query=mysql_query("select * from test order by id asc, RAND() limit 15"); $tags=""; while ($eachData=mysql_fetch_array($query)) { $additionalTags=$eachData['tags']; if ($tags=="") { $tags.=$additionalTags; } else { $tags.=$tags.",".$additionalTags; } } $tags=explode(",", $tags); $newTags=array(); foreach ($tags as $tag) { $tag=trim($tag); if ($tag!="") { if (!in_array($tag, $newTags)) { $newTags[]=$tag; } } } $random_newTags=array_rand($newTags, 50); Now I have huge records on the database, and because of that; rand() is performing very slow and sometimes it doesn't work. So can anyone let me know how to handle this situation correctly so that my page will work normally.

    Read the article

  • Very slow guards in my monadic random implementation (haskell)

    - by danpriduha
    Hi! I was tried to write one random number generator implementation, based on number class. I also add there Monad and MonadPlus instance. What mean "MonadPlus" and why I add this instance? Because of I want to use guards like here: -- test.hs -- import RandomMonad import Control.Monad import System.Random x = Rand (randomR (1 ::Integer, 3)) ::Rand StdGen Integer y = do a <-x guard (a /=2) guard (a /=1) return a here comes RandomMonad.hs file contents: -- RandomMonad.hs -- module RandomMonad where import Control.Monad import System.Random import Data.List data RandomGen g => Rand g a = Rand (g ->(a,g)) | RandZero instance (Show g, RandomGen g) => Monad (Rand g) where return x = Rand (\g ->(x,g)) (RandZero)>>= _ = RandZero (Rand argTransformer)>>=(parametricRandom) = Rand funTransformer where funTransformer g | isZero x = funTransformer g1 | otherwise = (getRandom x g1,getGen x g1) where x = parametricRandom val (val,g1) = argTransformer g isZero RandZero = True isZero _ = False instance (Show g, RandomGen g) => MonadPlus (Rand g) where mzero = RandZero RandZero `mplus` x = x x `mplus` RandZero = x x `mplus` y = x getRandom :: RandomGen g => Rand g a ->g ->a getRandom (Rand f) g = (fst (f g)) getGen :: RandomGen g => Rand g a ->g -> g getGen (Rand f) g = snd (f g) when I run ghci interpreter, and give following command getRandom y (mkStdGen 2000000000) I can see memory overflow on my computer (1G). It's not expected, and if I delete one guard, it works very fast. Why in this case it works too slow? What I do wrong?

    Read the article

  • Five unique, random numbers from a subset

    - by tau
    I know similar questions come up a lot and there's probably no definitive answer, but I want to generate five unique random numbers from a subset of numbers that is potentially infinite (maybe 0-20, or 0-1,000,000). The only catch is that I don't want to have to run while loops or fill an array. My current method is to simply generate five random numbers from a subset minus the last five numbers. If any of the numbers match each other, then they go to their respective place at the end of the subset. So if the fourth number matches any other number, it will bet set to the 4th from the last number. Does anyone have a method that is "random enough" and doesn't involve costly loops or arrays? Please keep in mind this a curiosity, not some mission-critical problem. I would appreciate it if everyone didn't post "why are you having this problem?" answers. I am just looking for ideas. Thanks a lot!

    Read the article

  • Using boost::random to select from an std::list where elements are being removed

    - by user144182
    See this related question on more generic use of the Boost Random library. My questions involves selecting a random element from an std::list, doing some operation, which could potentally include removing the element from the list, and then choosing another random element, until some condition is satisfied. The boost code and for loop look roughly like this: // create and insert elements into list std::list<MyClass> myList; //[...] // select uniformly from list indices boost::uniform_int<> indices( 0, myList.size()-1 ); boost::variate_generator< boost::mt19937, boost::uniform_int<> > selectIndex(boost::mt19937(), indices); for( int i = 0; i <= maxOperations; ++i ) { int index = selectIndex(); MyClass & mc = myList.begin() + index; // do operations with mc, potentially removing it from myList //[...] } My problem is as soon as the operations that are performed on an element result in the removal of an element, the variate_generator has the potential to select an invalid index in the list. I don't think it makes sense to completely recreate the variate_generator each time, especially if I seed it with time(0).

    Read the article

  • math.Random isn't working right

    - by RandomlyKnighted
    I'm trying to simulate a coin flip using the code below. public class Coin { public static double result; int[] count = new count[2]; public static void flip() { result = Math.random(); } public static boolean isHeads() { if (result == 0.0) { count[0]++; return false; } else { count[1]++; return true; } } public static void main(String[] args) { flip(); isHeads(); System.out.println(count[0]); System.out.println(count[1]); } } For some reason Eclipse says that the import java.util.Random; is never used even though I'm clearly using it. I didn't put my for loop into the code above but it loops n number of times and then outputs the result. No matter how many times it loops it always returns that the result is greater than 0.0 which can't be right. Am I calling Math.random incorrectly?

    Read the article

  • finding a string of random characters (with possible errors) within a large string of random charact

    - by mike
    I am trying to search a large string w/o spaces for a smaller string of characters. using regex I can easily find perfect matches but I can't figure out how to find partial matches. by partial matches i mean one or two extra characters in the string or one or two characters that have been changed, or one of each. the first and last characters will always match though. this would be similar to a spell checker but there are no spaces and the strings dont contain actual words, just random hex digits. i figured a way to find the string if there are no extra characters using indexOf(string.charAt(0)) and indexOf(charAt(string.length()-1) and looping through the characters between the two indexes. but this can be problematic when dealing with randomized characters because of the possibility of finding the first and last characters at the correct spacing but none of the middle characters matching. i've been scratching my head for hours on this issue. any ideas?

    Read the article

  • spring MVC sample web app

    - by Don
    Hi, I'm looking for an example Spring MVC 2.5 web app that I can easily: Setup as a project in Eclipse Deploy to a local app server (using Ant/Maven) There are a couple of example applications included with the Spring distribution ('petclinic' and 'jpetstore'), but they don't provide any Eclipse project files (or a way to generate them). They also seem a bit complicated for my needs, e.g. require a local database to be setup. Thanks, Don

    Read the article

  • Generating Random Paired Images in C#

    - by Lemon
    im trying create cards matching game. normally these type of games they match paired cards together (with the same file name "A.jpg with A.jpg") but in my case, im matching cards with different names "B.jpg with A.jpg" (correct), "C.jpg with D.jpg" (correct) but with "B.jpg with C.jpg" (incorrect answer). A.jpg-B.jpg <--correct C.jpg-D.jpg <--correct E.jpg-F.jpg <--correct i face a problem when i generate the cards in random. I manage to generate random cards but i dont manage to generate it with their paired onces. Below is an illustration of the problem A.jpg-B.jpg <--correct C.jpg-F.jpg <--incorrect so how should i code it so that it always generate with their paired onces, so that my game can proceed?

    Read the article

  • Timer with random seconds ¿How to update the random seconds?

    - by benLIVE
    I have a timer "tmr_sendCesta" which must be called each x seconds between 1 and 3 seconds. The problem is the timer "tmr_sendCesta" is called only one time, and the random seconds is never updated. I need to call the function "createCesta" each x seconds randomly. Any idea how to do it? function createCesta() cesta = display.newImageRect("cesta.png", 100, 55) cesta.x = -110 cesta.y = screenH - 110 cesta.name = "cesta" physics.addBody( cesta, physicsData:get("cestaSmall")) grupoCesta:insert(cesta) transition.to(cesta, {time = 4000, x = screenW + 110}) end function scene:enterScene( event ) local group = self.view physics.start() Runtime:addEventListener("touch", touchScreen) Runtime:addEventListener( "collision", onCollision ) tmr_sendCesta = timer.performWithDelay((math.random(1000, 3000), randomCesta, 0) end

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >