Search Results

Search found 5163 results on 207 pages for 'random'.

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

  • ArrayList of Entites Random Movement

    - by opiop65
    I have an arraylist of entites that I want to move randomly. No matter what I do, they won't move. Here is my female class: import java.awt.Graphics2D; import java.awt.Image; import java.awt.Rectangle; import java.util.Random; import javax.swing.ImageIcon; public class Female extends Entity { static int femaleX = 0; static int femaleY = 0; double walkSpeed = .1f; Random rand = new Random(); int random; int dir; Player player; public Female(int posX, int posY) { super(posX, posY); } public void update() { posX += femaleX; posY += femaleY; } public void draw(Graphics2D g2d) { g2d.drawImage(getFemaleImg(), posX, posY, null); if (Player.showBounds == true) { g2d.draw(getBounds()); } } public Image getFemaleImg() { ImageIcon ic = new ImageIcon("res/female.png"); return ic.getImage(); } public Rectangle getBounds() { return new Rectangle(posX, posY, getFemaleImg().getHeight(null), getFemaleImg().getWidth(null)); } public void moveFemale() { random = rand.nextInt(3); System.out.println(random); if (random == 0) { dir = 0; posX -= (int) walkSpeed; } } } And here is how I update the female class in the main class: public void actionPerformed(ActionEvent ae) { player.update(); for(int i = 0; i < females.size(); i++){ Female tempFemale = females.get(i); tempFemale.update(); } repaint(); } If I do something like this(in the female update method): public void update() { posX += femaleX; posY += femaleY; posX -= walkSpeed; } The characters move with no problem. Why is this?

    Read the article

  • Create many constrained, random permutation of a list

    - by Eyal
    I need to make a random list of permutations. The elements can be anything but assume that they are the integers 0 through x-1. I want to make y lists, each containing z elements. The rules are that no list may contain the same element twice and that over all the lists, the number of times each elements is used is the same (or as close as possible). For instance, if my elements are 0,1,2,3, y is 6, and z is 2, then one possible solution is: 0,3 1,2 3,0 2,1 0,1 2,3 Each row has only unique elements and no element has been used more than 3 times. If y were 7, then 2 elements would be used 4 times, the rest 3.

    Read the article

  • Multi-part gzip file random access (in Java)

    - by toluju
    This may fall in the realm of "not really feasible" or "not really worth the effort" but here goes. I'm trying to randomly access records stored inside a multi-part gzip file. Specifically, the files I'm interested in are compressed Heretrix Arc files. (In case you aren't familiar with multi-part gzip files, the gzip spec allows multiple gzip streams to be concatenated in a single gzip file. They do not share any dictionary information, it is simple binary appending.) I'm thinking it should be possible to do this by seeking to a certain offset within the file, then scan for the gzip magic header bytes (i.e. 0x1f8b, as per the RFC), and attempt to read the gzip stream from the following bytes. The problem with this approach is that those same bytes can appear inside the actual data as well, so seeking for those bytes can lead to an invalid position to start reading a gzip stream from. Is there a better way to handle random access, given that the record offsets aren't known a priori?

    Read the article

  • Random noise in Solr score

    - by Andrea Campi
    I am looking for a way of introducing random noise into my scoring function, and I'm at a loss on how to best proceed. Some background: We use Solr for a web application that manages large-ish sets of photos for agencies. One customer has an interesting requirement for scoring: 'quality' field, maintained by editors, from 1 (highest) to 3 (lowest); 'date' field, boosting more recent photos; I would probably use a logarithmic function; However, due to how the stock photo market works, this will likely result in many similar photos appearing together. Their request is to give 'quality' a large boost, but introduce some randomness so that photos will not appear in a strict date order. Any idea? EDITED: a key requirement is to have "stable" query results: if I search twice for "tropical island" I can get a slightly different result set, but if I ask for the first page, then the second, then the first, I'd better get the same results :)

    Read the article

  • Random List of millions of elements in Python Efficiently

    - by eWizardII
    Hello, I have read this answer potentially as the best way to randomize a list of strings in Python. I'm just wondering then if that's the most efficient way to do it because I have a list of about 30 million elements via the following code: import json from sets import Set from random import shuffle a = [] for i in range(0,193): json_data = open("C:/Twitter/user/user_" + str(i) + ".json") data = json.load(json_data) for j in range(0,len(data)): a.append(data[j]['su']) new = list(Set(a)) print "Cleaned length is: " + str(len(new)) ## Take Cleaned List and Randomize it for Analysis shuffle(new) If there is a more efficient way to do it, I'd greatly appreciate any advice on how to do it. Thanks,

    Read the article

  • Generating a random displacement on the unit sphere

    - by becko
    Given a unit vector n, I need to generate, as fast as possible, another random unit vector m. The deviation of m from n should be on the order of a positive parameter sigma, and the distribution of m on the unit sphere should be symmetrical around n. I have no specific requirements on the representation of unit vectors, so you can use spherical angles, Cartesian coordinates, or whatever turns out to be convenient. Also, there are no precise requirements on the probability distributions used, as long as it decays when m deviates more than sigma from n. I am working with gsl and C. I have come up with a somewhat convoluted method using Cartesian coordinates. I will post it later if it is useful, but I would like to see people's ideas.

    Read the article

  • Get `n` random values between 2 numbers having average `x`

    - by Somnath Muluk
    I want to get n random numbers(e.g n=16)(whole numbers) between 1 to 5(including both) so that average is x. x can be any value between (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5). I am using PHP. e.g. Suppose I have average x= 3. Then required 16 whole numbers between 1 to 5(including both). like (1,5,3,3,3,3,2,4,2,4,1,5,1,5,3,3) Update: if x=3.5 means average of 16 numbers should be between 3.5 to 4. and if x=4 means average of 16 numbers should be between 4 to 4.5 and if x=5 means all numbers are 5

    Read the article

  • Random numbers from binomial distribution

    - by Sarah
    I need to generate quickly lots of random numbers from binomial distributions for dramatically different trial sizes (most, however, will be small). I was hoping not to have to code an algorithm by hand (see, e.g., this related discussion from November), because I'm a novice programmer and don't like reinventing wheels. It appears Boost does not supply a generator for binomially distributed variates, but TR1 and GSL do. Is there a good reason to choose one over the other, or is it better that I write something customized to my situation? I don't know if this makes sense, but I'll alternate between generating numbers from uniform distributions and binomial distributions throughout the program, and I'd like for them to share the same seed and to minimize overhead. I'd love some advice or examples for what I should be considering.

    Read the article

  • Call random function on percents?

    - by Angelena Godkin
    I cannot figure this out. I need a solution to call a random function for it's percent. Ex. there is 10% chances that the script calls subscriptions() and 3% chance that the system call the function "specialitems()". I am stuck in this, so i hope someone can help me with this brainkiller. <?php class RandomGifts { public $chances = ''; public function __construct($user) { $this->user = $user; //Find percent for each function $this->chances = array( 'subscriptions' => 10, // 10% 'specialitems' => 3, // 5% 'normalitems' => 30, // 40% 'fuser' => 50, // 70% 'giftcards' => 7, // 7% ); //This should call the function which has been calculated. self::callFunction(?); } public function subscriptions(){} public function specialitems(){} public function normalitems(){} public function fuser(){} public function giftcards(){} } ?>

    Read the article

  • Relative probabilities using random number gen

    - by CyberShot
    If I have relative probabilities of events A, B, C occurring. i.e P(A) = 0.45, P(B) = 0.35, P(C) = 0.20, How do I do represent this using a random number generator between 0 and 1? i.e. R = rand(0,1) if (R < 0.45) event A else if(R < 0.35) event B else if(R < 0.20) event C The above works for two events A,B but I think the above is wrong for three or more since there is overlapping. This is obviously a very simple question and the answer should be immediately evident, but I'm just too stupid to see it.

    Read the article

  • How to do a random-and-unique generator?

    - by javaLearner.java
    I already wrote a random generator which take arguments a and b, where a is minimun and b is maximum value, like this randomGenerator(int a, int b) What I want to do next is: Using a loop, then generate unique number from a to b. Example: I want to have 8 unique numbers, int a = 1; int b = 10; int value; If I do the loop, there is a high % that same number will appear more than once. Any idea how to do it? My own way is: while(int i <= 8){ randomGenerator(a,b); // if value is not in array, then insert into array } I am stuck at the comment part. Is there any way to check if a variable is exists in an array?

    Read the article

  • Random movement of wandering monsters in x & y axis in LibGDX

    - by Vishal Kumar
    I am making a simple top down RPG game in LibGDX. What I want is ... the enemies should wander here and there in x and y directions in certain interval so that it looks natural that they are guarding something. I spend several hours doing this but could not achieve what I want. After a long time of coding, I came with this code. But what I observed is when enemies come to an end of x or start of x or start of y or end of y of the map. It starts flickering for random intervals. Sometimes they remain nice, sometimes, they start flickering for long time. public class Enemy extends Sprite { public float MAX_VELOCITY = 0.05f; public static final int MOVING_LEFT = 0; public static final int MOVING_RIGHT = 1; public static final int MOVING_UP = 2; public static final int MOVING_DOWN = 3; public static final int HORIZONTAL_GUARD = 0; public static final int VERTICAL_GUARD = 1; public static final int RANDOM_GUARD = 2; private float startTime = System.nanoTime(); private static float SECONDS_TIME = 0; private boolean randomDecider; public int enemyType; public static final float width = 30 * World.WORLD_UNIT; public static final float height = 32 * World.WORLD_UNIT; public int state; public float stateTime; public boolean visible; public boolean dead; public Enemy(float x, float y, int enemyType) { super(x, y); state = MOVING_LEFT; this.enemyType = enemyType; stateTime = 0; visible = true; dead = false; boolean random = Math.random()>=0.5f ? true :false; if(enemyType == HORIZONTAL_GUARD){ if(random) velocity.x = -MAX_VELOCITY; else velocity.x = MAX_VELOCITY; } if(enemyType == VERTICAL_GUARD){ if(random) velocity.y = -MAX_VELOCITY; else velocity.y = MAX_VELOCITY; } if(enemyType == RANDOM_GUARD){ //if(random) //velocity.x = -MAX_VELOCITY; //else //velocity.y = MAX_VELOCITY; } } public void update(Enemy e, float deltaTime) { super.update(deltaTime); e.stateTime+= deltaTime; e.position.add(velocity); // This is for updating the Animation for Enemy Movement Direction. VERY IMPORTANT FOR REAL EFFECTS updateDirections(); //Here the various movement methods are called depending upon the type of the Enemy if(e.enemyType == HORIZONTAL_GUARD) guardHorizontally(); if(e.enemyType == VERTICAL_GUARD) guardVertically(); if(e.enemyType == RANDOM_GUARD) guardRandomly(); //quadrantMovement(e, deltaTime); } private void guardHorizontally(){ if(position.x <= 0){ velocity.x= MAX_VELOCITY; velocity.y= 0; } else if(position.x>= World.mapWidth-width){ velocity.x= -MAX_VELOCITY; velocity.y= 0; } } private void guardVertically(){ if(position.y<= 0){ velocity.y= MAX_VELOCITY; velocity.x= 0; } else if(position.y>= World.mapHeight- height){ velocity.y= -MAX_VELOCITY; velocity.x= 0; } } private void guardRandomly(){ if (System.nanoTime() - startTime >= 1000000000) { SECONDS_TIME++; if(SECONDS_TIME % 5==0) randomDecider = Math.random()>=0.5f ? true :false; if(SECONDS_TIME>=30) SECONDS_TIME =0; startTime = System.nanoTime(); } if(SECONDS_TIME <=30){ if(randomDecider && position.x >= 0) velocity.x= -MAX_VELOCITY; else{ if(position.x < World.mapWidth-width) velocity.x= MAX_VELOCITY; else velocity.x= -MAX_VELOCITY; } velocity.y =0; } else{ if(randomDecider && position.y >0) velocity.y= -MAX_VELOCITY; else velocity.y= MAX_VELOCITY; velocity.x =0; } /* //This is essential so as to keep the enemies inside the boundary of the Map if(position.x <= 0){ velocity.x= MAX_VELOCITY; //velocity.y= 0; } else if(position.x>= World.mapWidth-width){ velocity.x= -MAX_VELOCITY; //velocity.y= 0; } else if(position.y<= 0){ velocity.y= MAX_VELOCITY; //velocity.x= 0; } else if(position.y>= World.mapHeight- height){ velocity.y= -MAX_VELOCITY; //velocity.x= 0; } */ } private void updateDirections() { if(velocity.x > 0) state = MOVING_RIGHT; else if(velocity.x<0) state = MOVING_LEFT; else if(velocity.y>0) state = MOVING_UP; else if(velocity.y<0) state = MOVING_DOWN; } public Rectangle getBounds() { return new Rectangle(position.x, position.y, width, height); } private void quadrantMovement(Enemy e, float deltaTime) { int temp = e.getEnemyQuadrant(e.position.x, e.position.y); boolean random = Math.random()>=0.5f ? true :false; switch(temp){ case 1: velocity.x = MAX_VELOCITY; break; case 2: velocity.x = MAX_VELOCITY; break; case 3: velocity.x = -MAX_VELOCITY; break; case 4: velocity.x = -MAX_VELOCITY; break; default: if(random) velocity.x = MAX_VELOCITY; else velocity.y =-MAX_VELOCITY; } } public float getDistanceFromPoint(float p1,float p2){ Vector2 v1 = new Vector2(p1,p2); return position.dst(v1); } private int getEnemyQuadrant(float x, float y){ Rectangle enemyQuad = new Rectangle(x, y, 30, 32); if(ScreenQuadrants.getQuad1().contains(enemyQuad)) return 1; if(ScreenQuadrants.getQuad2().contains(enemyQuad)) return 2; if(ScreenQuadrants.getQuad3().contains(enemyQuad)) return 3; if(ScreenQuadrants.getQuad4().contains(enemyQuad)) return 4; return 0; } } Is there a better way of doing this. I am new to game development. I shall be very grateful to any help or reference.

    Read the article

  • Java: random long number in 0 <= x < n range.

    - by Vilius Normantas
    Random class has a method to generate random int in a given range. For example: Random r = new Random(); int x = r.nextInt(100); This would generate an int number more or equal to 0 and less than 100. I'd like to do exactly the same with long number. long y = magicRandomLongGenerator(100); Random class has only nextLong(), but it doesn't allow to set range.

    Read the article

  • Which Is The Best Way Of Creating Random Value ???

    - by Meko
    I am triying to create random value for my game to show enemies on screen. BUt it some times shows 2 together some times 3 ...I want to ask that which is the best formul for creating random value.. This is my so far random value random = 1 * (int) (Math.random() * 100);

    Read the article

  • Can an algorithmic process ever give true random numbers ?

    - by Arkapravo
    I have worked with random functions in python,ruby, MATLAB, Bash and Java. Nearly every programming language has a function to generate Random numbers. However, these apparently random sequences are termed as pseudo-random number sequences as the generation follows a deterministic approach, and the sequence seems to repeat (usually with a very large period). My question, can an algorithmic/programming process ever yield true random numbers ? The questions probably is more of theoretical computer science than just programming !

    Read the article

  • how to make a name from random numbers?

    - by blood
    my program makes a random name that could have a-z this code makes a 16 char name but :( my code wont make the name and idk why :( can anyone show me what's wrong with this? char name[16]; void make_random_name() { byte loop = -1; for(;;) { loop++; srand((unsigned)time(0)); int random_integer; random_integer = (rand()%10)+1; switch(random_integer) { case '1': name[loop] = 'A'; break; case '2': name[loop] = 'B'; break; case '3': name[loop] = 'C'; break; case '4': name[loop] = 'D'; break; case '5': name[loop] = 'E'; break; case '6': name[loop] = 'F'; break; case '7': name[loop] = 'G'; break; case '8': name[loop] = 'Z'; break; case '9': name[loop] = 'H'; break; } cout << name << "\n"; if(loop > 15) { break; } } }

    Read the article

  • Java Random Slowdowns on Mac OS cont'd

    - by javajustice
    I asked this question a few weeks ago, but I'm still having the problem and I have some new hints. The original question is here: http://stackoverflow.com/questions/1651887/java-random-slowdowns-on-mac-os Basically, I have a java application that splits a job into independent pieces and runs them in separate threads. The threads have no synchronization or shared memory items. The only resources they do share are data files on the hard disk, with each thread having an open file channel. Most of the time it runs very fast, but occasionally it will run very slow for no apparent reason. If I attach a CPU profiler to it, then it will start running quickly again. If I take a CPU snapshot, it says its spending most of its time in "self time" in a function that doesn't do anything except check a few (unshared unsynchronized) booleans. I don't know how this could be accurate because 1, it makes no sense, and 2, attaching the profiler seems to knock the threads out of whatever mode they're in and fix the problem. Also, regardless of whether it runs fast or slow, it always finishes and gives the same output, and it never dips in total cpu usage (in this case ~1500%), implying that the threads aren't getting blocked. I have tried different garbage collectors, different sizings the parts of the memory space, writing data output to non-raid drives, and putting all data output in threads separate the main worker threads. Does anyone have any idea what kind of problem this could be? Could it be the operating system (OS X 10.6.2) ? I have not been able to duplicate it on a windows machine, but I don't have one with a similar hardware configuration.

    Read the article

  • Load random swf object with jquery

    - by Eggnog
    I'm working on a site that utilizes full screen background video. I have three flash videos I'd like to load into the page which would be displayed randomly on page refresh. I know you can achieve this through action script loading the movies into one main .swf, but I'm rubbish with Flash and am looking for an alternative solution. My search so far has uncovered a method using jquery. Unfortunately my attempts to implement it have failed. I'm hoping someone more knowledgeable than myself can tell me if this technique is valid or what I'm doing wrong. Here's my code to date: <script type="text/javascript" src="files/js/swfobject.js"></script> <script type="text/javascript"> $(document).ready(function() { var sPath; var i = Math.floor(Math.random()*2); switch(i) { case 0: sPath = "flash/homepage_video.swf"; break; case 1: sPath = "flash/homepage_video.swf"; break; } // load the flash version of the image var so = new SWFObject(sPath, "flash-background", "100%", "100%"); so.addParam("scale", "exactFit"); so.addParam("movie", sPath); // NOTE: the sPath variable is also used here so.addParam("quality", "high"); so.addParam("wmode", "transparent"); so.write("homeBackground"); // NOTE: The value in this call to write() MUST match the name of the // HTML element (<div>) you're expecting the swf to show up in }); </script> <body> <div id="homeBackground"> <p>This is alternative content</p> </div> </body> I'm open to other suggestions that don't involve jquery (php perhaps). Thanks.

    Read the article

  • Stable/repeatable random sort (MySQL, Rails)

    - by Matt Rogish
    I'd like to paginate through a randomly sorted list of ActiveRecord models (rows from MySQL database). However, this randomization needs to persist on a per-session basis, so that other people that visit the website also receive a random, paginate-able list of records. Let's say there are enough entities (tens of thousands) that storing the randomly sorted ID values in either the session or a cookie is too large, so I must temporarily persist it in some other way (MySQL, file, etc.). Initially I thought I could create a function based on the session ID and the page ID (returning the object IDs for that page) however since the object ID values in MySQL are not sequential (there are gaps), that seemed to fall apart as I was poking at it. The nice thing is that it would require no/minimal storage but the downsides are that it is likely pretty complex to implement and probably CPU intensive. My feeling is I should create an intersection table, something like: random_sorts( sort_id, created_at, user_id NULL if guest) random_sort_items( sort_id, item_id, position ) And then simply store the 'sort_id' in the session. Then, I can paginate the random_sorts WHERE sort_id = n ORDER BY position LIMIT... as usual. Of course, I'd have to put some sort of a reaper in there to remove them after some period of inactivity (based on random_sorts.created_at). Unfortunately, I'd have to invalidate the sort as new objects were created (and/or old objects being removed, although deletion is very rare). And, as load increases the size/performance of this table (even properly indexed) drops. It seems like this ought to be a solved problem but I can't find any rails plugins that do this... Any ideas? Thanks!!

    Read the article

  • Include php code within echo from a random text

    - by lisa
    I want to display a php code at random and so for I have <?php // load the file that contain thecode $adfile = "code.txt"; $ads = array(); // one line per code $fh = fopen($adfile, "r"); while(!feof($fh)) { $line = fgets($fh, 10240); $line = trim($line); if($line != "") { $ads[] = $line; } } // randomly pick an code $num = count($ads); $idx = rand(0, $num-1); echo $ads[$idx]; ?> The code.txt has lines like <?php print insert_proplayer( array( "width" => "600", "height" => "400" ), "http://www.youtube.com/watch?v=xnPCpCVepCg"); ?> Proplayer is a wordpress plugin that displays a video. The codes in code.txt work well, but not when I use the pick line from code.txt. Instead of the full php line I get: "width" => "600", "height" => "400" ), "http://www.youtube.com/watch?v=xnPCpCVepCg"); ?> How can I make the echo show the php code, rather than a txt version of the php code?

    Read the article

  • random, Graphics point ,searching- algorithm, via dual for loop set

    - by LoneXcoder
    hello and thanks for joining me in my journey to the custom made algorithm for "guess where the pixel is" this for Loop set (over Point.X, Point.Y), is formed in consecutive/linear form: //Original\initial Location Point initPoint = new Point(150, 100); // No' of pixels to search left off X , and above Y int preXsrchDepth, preYsrchDepth; // No' of pixels to search to the right of X, And Above Y int postXsrchDepth, postYsrchDepth; preXsrchDepth = 10; // will start search at 10 pixels to the left from original X preYsrchDepth = 10; // will start search at 10 pixels above the original Y postXsrchDepth = 10; // will stop search at 10 pixels to the right from X postYsrchDepth = 10; // will stop search at 10 pixels below Y int StopXsearch = initPoint.X + postXsrchDepth; //stops X Loop itarations at initial pointX + depth requested to serch right of it int StopYsearch = initPoint.Y + postYsrchDepth; //stops Y Loop itarations at initial pointY + depth requested below original location int CountDownX, CountDownY; // Optional not requierd for loop but will reports the count down how many iterations left (unless break; triggerd ..uppon success) Point SearchFromPoint = Point.Empty; //the point will be used for (int StartX = initPoint.X - preXsrchDepth; StartX < StopXsearch; StartX++) { SearchFromPoint.X = StartX; for (int StartY = initPoint.Y - preYsrchDepth; StartY < StpY; StartY++) { CountDownX = (initPoint.X - StartX); CountDownY=(initPoint.Y - StartY); SearchFromPoint.Y = StartY; if (SearchSuccess) { same = true; AAdToAppLog("Search Report For: " + imgName + "Search Completed Successfully On Try " + CountDownX + ":" + CountDownY); break; } } } <-10 ---- -5--- -1 X +1--- +5---- +10 what i would like to do is try a way of instead is have a little more clever approach <+8---+5-- -8 -5 -- +2 +10 X -2 - -10 -8-- -6 ---1- -3 | +8 | -10 Y +1 -6 | | +9 .... I do know there's a wheel already invented in this field (even a full-trailer truck amount of wheels (: ) but as a new programmer, I really wanted to start of with a simple way and also related to my field of interest in my project. can anybody show an idea of his, he learnt along the way to Professionalism in algorithm /programming having tests to do on few approaches (kind'a random cleverness...) will absolutely make the day and perhaps help some others viewing this page in the future to come it will be much easier for me to understand if you could use as much as possible similar naming to variables i used or implenet your code example ...it will be Greatly appreciated if used with my code sample, unless my metod is a realy flavorless. p.s i think that(atleast as human being) the tricky part is when throwing inconsecutive numbers you loose track of what you didn't yet use, how do u take care of this too . thanks allot in advance looking forward to your participation !

    Read the article

  • RMI applet is making requests on random ports and blocked consequently

    - by Dan
    /// I have set up RMI system successfully on local ubuntu srver. Registry port 1099 and remote object export on 1100(fixed by calling super(1100)) Now I am trying to make it work on Ubuntu over internet with a public IP. I could bind service properly with public ip.But the client applet is trying to connect to ubuntu server at random ports. Below is the error thrown by client applet: // Exception network: Connecting public-ip:1100 with proxy=DIRECT network: Connecting public-ip/cgi-bin/java-rmi.cgi?forward=1099 with proxy=DIRECT network: Connecting public-ip:3733 with proxy=DIRECT network: Connecting public-ip:3721 with proxy=DIRECT // java.rmi.ConnectException: Connection refused to host: public-ip; nested exception is: java.net.ConnectException: Connection refused: connect at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ... // // I have only 2 ports open on server, i.e., 1099(registry) and 1100(export). How can I fix ports in applet requests such that it does always connect server on same open port? // // Another issue.As I have bound service on public IP i.e. //public-ip:1099/ServiceName, a job running on server to send message to clinets is not able to make request to RMI service. public-ip URL does not work on same machine,i.e., server.Do you think I should use fixed socket factory?If so please give me code snippet and guide me how i can set it up. //Exception java.rmi.ConnectException: Connection refused to host: public-ip; nested exception is: java.net.ConnectException: Connection refused at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216) at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:128) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194) at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148) at $Proxy5.getUserID(Unknown Source) at rmi.source.xxxxxx$JobScheduler.run(xxxxServerImpl.java:293) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505) Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at java.net.Socket.(Socket.java:425) at java.net.Socket.(Socket.java:208) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613) ... 9 more Coould you please help me? Thanks a lot in advance. Dan

    Read the article

  • Strange problem with Random Access Filing in C++

    - by sam
    This is a simple random access filing program . The problem arises where i want to write data randomly. If I write any where in the file the previous records are set to 0. the last 1 which is being entered currently holds the correct value all others =0. This is the code #include <iostream> #include<fstream> #include<string> using namespace std; class name { int id; int pass; public: void writeBlank(); void writedata(); void readdata(); void readall(); int getid() { return id; } int getpass() { return pass; } void setid(int i) { id=i; } void setpass(int p) { pass=p; } }; void name::writeBlank() { name person; person.setid(0); person.setpass(0); int i; ofstream out("pass.txt",ios::binary); if ( !out ) { cout << "File could not be opened." << endl; } for(i=0;i<10;i++) //make 10 records { cout<<"Put pointer is at: "<<out.tellp()<<endl; cout<<"Blank record "<<i<<" is: "<<person.getid()<<" "<<person.getpass()<<" and size: "<<sizeof(person)<<endl; cout<<"Put pointer is at: "<<out.tellp()<<endl; out.write(reinterpret_cast< const char * >(&person),sizeof(name)); } } void name::writedata() { ofstream out("pass.txt",ios::binary|ios::out); name n1; int iD,p; cout<<"ID?"; cin>>iD; n1.setid(iD); cout<<"Enter password"; cin>>p; n1.setpass(p); if (!out ) { cout << "File could not be opened." << endl; } out.seekp((n1.getid()-1)*sizeof(name),ios::beg); //pointer moves to desired location where we have to store password according to its ID(index) cout<<"File pointer is at: "<<out.tellp()<<endl; out.write(reinterpret_cast<const char*> (&n1), sizeof(name)); //write on that pointed location } void name::readall() { name n1; ifstream in("pass.txt",ios::binary); if ( !in ) { cout << "File could not be opened." << endl; } in.read( reinterpret_cast<char *>(&n1), sizeof(name) ); while ( !in.eof() ) { // display record cout<<endl<<"password at this index is:"<<n1.getpass()<<endl; cout<<"File pointer is at: "<<in.tellg()<<endl; // read next from file in.read( reinterpret_cast< char * >(&n1), sizeof(name)); } // end while } void name::readdata() { ifstream in("pass.txt",ios::binary); if ( !in ) { cout << "File could not be opened." << endl; } in.seekg((getid()-1)*sizeof(name)); //pointer moves to desired location where we have to read password according to its ID(index) cout<<"File pointer is at: "<<in.tellg()<<endl; in.read((char* )this,sizeof(name)); //reads from that pointed location cout<<endl<<"password at this index is:"<<getpass()<<endl; } int main() { name n1; cout<<"Enter 0 to write blank records"<<endl; cout<<"Enter 1 for new account"<<endl; cout<<"Enter 2 to login"<<endl; cout<<"Enter 3 to read all"<<endl; cout<<"Enter 9 to exit"<<endl; int option; cin>>option; while(option==0 || option==1 || option==2 || option==3) { if (option == 0) n1.writeBlank(); if(option==1) { /*int iD,p; cout<<"ID?"; cin>>iD; n1.setid(iD); cout<<"Enter password"; cin>>p; n1.setpass(p);*/ n1.writedata(); } int ind; if(option==2) { cout<<"Index?"; cin>>ind; n1.setid(ind); n1.readdata(); } if(option == 3) n1.readall(); cout<<"Enter 0 to write blank records"<<endl; cout<<"Enter 1 for new account"<<endl; cout<<"Enter 2 to login"<<endl; cout<<"Enter 3 to read all"<<endl; cout<<"Enter 9 to exit"<<endl; cin>>option; } } I Cant understand Y the previous records turn 0.

    Read the article

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