Search Results

Search found 29841 results on 1194 pages for 'random number generator'.

Page 8/1194 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • 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

  • Data Generator Source Adapter

    This component needs little explanation. It generates random integer (DT_I4) and string (DT_WSTR) data and places them in the pipeline. You specify how many columns of each you would like and for any string columns you pass a fixed length value. You then need to specify how many rows in total you require to be generated. This component is used by us to do testing of the pipeline and components downstream. Previously we would have used a script component (as a source) to generate the rows but found ourselves rewriting the code too often so created this component. Screenshots SQL Server 2005 Integration Services SQL Server 2008/2012 Integration Services The component is provided as an MSI file, however to complete the installation, you will have to add the transformation to the Visual Studio toolbox manually. Right-click the toolbox, and select Choose Items.... Select the SSIS Data Flow Items tab, and then check the Data Generator Source from the list. Downloads The Data Generator Source Adapter is available for SQL Server 2005, SQL Server 2008 (includes R2) and SQL Server 2012. Please choose the version to match your SQL Server version, or you can install multiple versions and use them side by side if you have more than one version of SQL Server installed. Data Generator Source Adapter for SQL Server 2005 Data Generator Source Adapter for SQL Server 2008 Data Generator Source Adapter for SQL Server 2012 Version History SQL Server 2012 Version 3.0.0.30 - SQL Server 2012 release. Includes upgrade support for both 2005 and 2008 packages to 2012. (5 Jun 2012) SQL Server 2008 Version 2.0.0.29 - SQL Server 2008 February 2008 CTP. Includes support for upgrade of 2005 packages. Simplified user interface. (4 Mar 2008) Version 2.0.0.27 - SQL Server 2008 November 2007 CTP. String columns will now use the default system code page. Previously string columns always used 1252. (15 Feb 2008) SQL Server 2005 Version 1.1.0.23 - SQL Server 2005 RTM Refresh. SP1 Compatibility Testing. (12 Jun 2006) Version 1.0.0.0 - SQL Server 2005 IDW 16 Sept CTP. Public release. (6 Oct 2005)

    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

  • Can you tell me why this generates time limit exceeded in spoj(Prime Number Generator)

    - by magiix
    #include<iostream> #include<string.h> #include<math.h> using namespace std; bool prime[1000000500]; void generate(long long end) { memset(prime,true,sizeof(prime)); prime[0]=false; prime[1]=false; for(long long i=0;i<=sqrt(end);i++) { if(prime[i]==true) { for(long long y=i*i;y<=end;y+=i) { prime[y]=false; } } } } int main() { int n; long long b,e; scanf("%d",&n); while(n--) { cin>>b>>e; generate(e); for(int i=b;i<e;i++) { if(prime[i]) printf("%d\n",i); } } return 0; } That's my code for spoj prime generator. Altought it generates the same output as another accepted code ..

    Read the article

  • Creating a smart text generator

    - by royrules22
    I'm doing this for fun (or as 4chan says "for teh lolz") and if I learn something on the way all the better. I took an AI course almost 2 years ago now and I really enjoyed it but I managed to forget everything so this is a way to refresh that. Anyway I want to be able to generate text given a set of inputs. Basically this will read forum inputs (or maybe Twitter tweets) and then generate a comment based on the learning. Now the simplest way would be to use a Markov Chain Text Generator but I want something a little bit more complex than that as the MKC basically only learns by word order (which word is more likely to appear after word x given the input text). I'm trying to see if there's something I can do to make it a little bit more smarter. For example I want it to do something like this: Learn from a large selection of posts in a message board but don't weight it too much For each post: Learn from the other comments in that post and weigh these inputs higher Generate comment and post See what other users' reaction to your post was. If good weigh it positively so you make more posts that are similar to the one made, and vice versa if negative. It's the weighing and learning from mistakes part that I'm not sure how to implement. I thought about Artificial Neural Networks (mainly because I remember enjoying that chapter) but as far as I can tell that's mainly used to classify things (i.e. given a finite set of choices [x1...xn] which x is this given input) not really generate anything. I'm not even sure if this is possible or if it is what should I go about learning/figuring out. What algorithm is best suited for this? To those worried that I will use this as a bot to spam or provide bad answers to SO, I promise that I will not use this to provide (bad) advice or to spam for profit. I definitely will not post it's nonsensical thoughts on SO. I plan to use it for my own amusement. Thanks!

    Read the article

  • Linq to SQL code generator features

    - by Anders Abel
    I'm very fond of Linq to SQL and the programming model it encourages. I think that in many cases when you are in control of both the database schema and the code it is not worth the effort to have different relational and object models for the data. Working with Linq to SQL makes it simple to have type safe data access from .NET, using the partial extension methods to implement business rules. Unfortunately I do not like the dbml designer due to the lack of a schema refresh function. So far I have used SqlMetal, but that lacks the customization options of the dbml designer. Because of that I've started working on a tool which regenerates the whole code file like SqlMetal, but has the ability to do the customizations that are available in the dbml designer (and maybe more in the future). The customizations will be described in an xml file which only contains those parts that shouldn't have default values. This should keep the xml file size down as well as the maintenance burden of it. To help me focus on the right features, I would like to know: What would be your favourite feature in a linq to sql code generator?

    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

  • 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

  • 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

  • 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

  • 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

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