Search Results

Search found 5712 results on 229 pages for 'j random coder'.

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

  • 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

  • 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

  • Whats wrong with my Random?

    - by David
    Here's my import statement: import java.util.*; Here it is in main: Random Rand = new Random() ; Here it is in a public void method : int a - 0 ; while (!done) { int a = Rand.nextInt(10) ; if (debug) stuff ; if (possibles[a]==1) done = true ; } Here's the error message i get: TicTacToe.java:85: cannot find symbol symbol : method nextInt(int) location: class Rand a = Rand.nextInt(10) ; ^ Whats going wrong here? it seems like i've done everything right to me.

    Read the article

  • PHP Get random paragraph

    - by Jack
    Anyone know how to get a random set of lines from a text file? I want to get a set of 3 lines with <br> on the front of each and display them through html. example: set 1 <br>Hi <br>what's your name <br>goodbye set 2 <br>stack <br>overflow <br>hi there set 3,4,5.... Choose one random set and display it. The sets of lines would be stored in a text file. Thanks a lot!

    Read the article

  • Best way to get a reasonably random key for MYSQL records

    - by Steve N
    Hi there, I need to generate a reasonably random unique key for a table. It should be something like a GUID for MYSQL. I've tried UUID, but it looks like only the first few characters are actually random- the rest are the same every time I insert them. Essentially, it is desirable for this key field to be very difficult to guess, even if you already have one known value in the column. What is the best way to do this, and how should I set up the field data type to store the value efficiently? Thank you, Steve

    Read the article

  • Pick Random String From Array

    - by atrljoe
    How do I go about picking a random string from my array but not picking the same one twice. string[] names = { "image1.png", "image2.png", "image3.png", "image4.png", "image5.png" }; Is this possible? I was thinking about using return strings[random.Next(strings.Length)]; But this has the possibility of returning the same string twice. Or am I wrong about this? Should I be using something else like a List to accomplish this. Any feedback is welcome.

    Read the article

  • Javascript : random number between variables issue

    - by Mayhem
    I've seen the other examples on this site but I just can't get it to work. I'm trying to generate a random number between 2 user input variables on a form. The numbers will always be positive numbers. min = document.getElementById('min').value; max = document.getElementById('max').value; waitTimer = Math.floor(Math.random() * (max - min + 1)) + min; When min = 5 / max = 10, waitTimer is sometimes returning results like 2, 4 and 28 and so on. What am I doing wrong?

    Read the article

  • Random walk- Brownian Motion

    - by Sam
    I've been assigned the project of creating a simple console app. that models brownian motion in a 2D plane. I wasn't given much information on how to do so (and I'm hoping that it's a pretty popular assignment so that I could get some insight) just that it relies on random number generation. I researched brownian motion for a little bit and saw some formulas that looked complicated, but by the description is just seems to have to move randomly within a certain number interval. Can anyone clarify? Am I to create a program that continually creates a random number in an interval and then modify the particles "x" and "y" coordinate or is there more to it? Thanks for any help.

    Read the article

  • Deterministic random number generator with context?

    - by user653133
    I am looking for a seeded random number generator that creates a pool of numbers as a context. It doesn't have to be too good. It is used for a game, but it is important, that each instance of the Game Engine has it's own pool of numbers, so that different game instances or even other parts of the game that use random numbers don't break the deterministic character of the generated numbers. Currently I am using rand() which obviously doesn't have this feature. Are there any c or objective-c generators that are capable of doing what I want? Best regards, Michael

    Read the article

  • Hibernate Criteria API: get n random rows

    - by hadrien
    I can't figure out how to fetch n random rows from a criteria instance: Criteria criteria = session.createCriteria(Table.class); criteria.add(Restrictions.eq('fieldVariable', anyValue)); ... Then what? I can't find any doc with Criteria API Does it mean I should use HQL instead? Thanx! EDIT: I get the number of rows by: int max = criteria.setProjecxtion(Projections.rowCount()).uniqueResult(); How do I fetch n random rows with indexes between 0 and max? Thx again!

    Read the article

  • Display random image when page loads without utilizing onload in the body tag

    - by Peachy
    I'm trying to create a fairly simple piece of JavaScript that displays a random image from an array each time the page loads. I need to figure out a way to get this running without adding code to the body tag. Is there a way to accomplish this without, say, an onload funtion placed in the body tag? Here's what I have that relies on the onLoad: ImageSwitch=new Array(); ImageSwitch[0]='1.jpg'; ImageSwitch[1]='2.jpg'; ImageSwitch[2]='3.jpg'; ImageSwitch[3]='4.jpg'; function swapImage() { document.getElementById("theImage").setAttribute("src", ImageSwitch[ Math.round(Math.random()*3)]) } Any alternative ideas to accomplish this? Thanks.

    Read the article

  • Randomly placing items script not working - sometimes items spawn in walls, sometimes items spawn in weird locations

    - by Timothy Williams
    I'm trying to figure out a way to randomly spawn items throughout my level, however I need to make sure they won't spawn inside another object (walls, etc.) Here's the code I'm currently using, it's based on the Physics.CheckSphere(); function. This runs OnLevelWasLoaded(); It spawns the items perfectly fine, but sometimes items spawn partway in walls. And sometimes items will spawn outside of the SpawnBox range (no clue why it does that.) //This is what randomly generates all the items. void SpawnItems () { if (Application.loadedLevelName == "Menu" || Application.loadedLevelName == "End Demo") return; //The bottom corner of the box we want to spawn items in. Vector3 spawnBoxBot = Vector3.zero; //Top corner. Vector3 spawnBoxTop = Vector3.zero; //If we're in the dungeon, set the box to the dungeon box and tell the items we want to spawn. if (Application.loadedLevelName == "dungeonScene") { spawnBoxBot = new Vector3 (8.857f, 0, 9.06f); spawnBoxTop = new Vector3 (-27.98f, 2.4f, -15); itemSpawn = dungeonSpawn; } //Spawn all the items. for (i = 0; i != itemSpawn.Length; i ++) { spawnedItem = null; //Zeroes out our random location Vector3 randomLocation = Vector3.zero; //Gets the meshfilter of the item we'll be spawning MeshFilter mf = itemSpawn[i].GetComponent<MeshFilter>(); //Gets it's bounds (see how big it is) Bounds bounds = mf.sharedMesh.bounds; //Get it's radius float maxRadius = new Vector3 (bounds.extents.x + 10f, bounds.extents.y + 10f, bounds.extents.z + 10f).magnitude * 5f; //Set which layer is the no walls layer var NoWallsLayer = 1 << LayerMask.NameToLayer("NoWallsLayer"); //Use that layer as your layermask. LayerMask layerMask = ~(1 << NoWallsLayer); //If we're in the dungeon, certain items need to spawn on certain halves. if (Application.loadedLevelName == "dungeonScene") { if (itemSpawn[i].name == "key2" || itemSpawn[i].name == "teddyBearLW" || itemSpawn[i].name == "teddyBearLW_Admiration" || itemSpawn[i].name == "radio") randomLocation = new Vector3(Random.Range(spawnBoxBot.x, -26.96f), Random.Range(spawnBoxBot.y, spawnBoxTop.y), Random.Range(spawnBoxBot.z, -2.141f)); else randomLocation = new Vector3(Random.Range(spawnBoxBot.x, spawnBoxTop.x), Random.Range(spawnBoxBot.y, spawnBoxTop.y), Random.Range(-2.374f, spawnBoxTop.z)); } //Otherwise just spawn them in the box. else randomLocation = new Vector3(Random.Range(spawnBoxBot.x, spawnBoxTop.x), Random.Range(spawnBoxBot.y, spawnBoxTop.y), Random.Range(spawnBoxBot.z, spawnBoxTop.z)); //This is what actually spawns the item. It checks to see if the spot where we want to instantiate it is clear, and if so it instatiates it. Otherwise we have to repeat the whole process again. if (Physics.CheckSphere(randomLocation, maxRadius, layerMask)) spawnedItem = Instantiate(itemSpawn[i], randomLocation, Random.rotation); else i --; //If we spawned something, set it's name to what it's supposed to be. Removes the (clone) addon. if (spawnedItem != null) spawnedItem.name = itemSpawn[i].name; } } What I'm asking for is if you know what's going wrong with this code that it would spawn stuff in walls. Or, if you could provide me with links/code/ideas of a better way to check if an item will spawn in a wall (some other function than Physics.CheckSphere). I've been working on this for a long time, and nothing I try seems to work. Any help is appreciated.

    Read the article

  • Help for creating a random String

    - by Max
    I need to create a random string which should be between the length of 6 to 10 but it sometimes generates only about the length of 3 to 5. Here's my code. Can anyone would be able to find out the problem? :( int lengthOfName = (int)(Math.random() * 4) + 6; String name = ""; /* randomly choosing a name*/ for (int j = 0; j <= lengthOfName; j++) { int freq = (int)(Math.random() * 100) + 1; if(freq <= 6){ name += "a"; }if(freq == 7 && freq == 8){ name += "b"; }if(freq >= 9 && freq <= 11){ name += "c"; }if(freq >= 12 && freq <= 15){ name += "d"; }if(freq >= 16 && freq <= 25){ name += "e"; }if(freq == 26 && freq == 27){ name += "f"; }if(freq == 28 && freq == 29){ name += "g"; }if(freq >= 30 && freq <= 33){ name += "h"; }if(freq >= 34 && freq <= 48){ name += "i"; }if(freq == 49 && freq == 50){ name += "j"; }if(freq >= 51 && freq <= 55){ name += "k"; }if(freq >= 56 && freq <= 60){ name += "l"; }if(freq == 61 && freq == 62){ name += "m"; }if(freq >= 63 && freq <= 70){ name += "n"; }if(freq >= 71 && freq <= 75){ name += "o"; }if(freq == 76 && freq == 77){ name += "p"; }if(freq == 78){ name += "q"; }if(freq >= 79 && freq <= 84){ name += "r"; }if(freq == 85 && freq == 86){ name += "s"; }if(freq == 87 && freq == 88){ name += "t"; }if(freq >= 89 && freq <= 93){ name += "u"; }if(freq == 94){ name += "v"; }if(freq == 95 && freq == 96){ name += "w"; }if(freq == 97){ name += "x"; }if(freq == 98 && freq == 99){ name += "y"; }if(freq == 100){ name += "z"; } }

    Read the article

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