I can't get this to work! (hard to describe in topic) (please read)

My other class, DivideGenes, is supposed to divide the genes created in Genes in half (to create a sperm cell). I do this by
1. copying the array
2. finding random indexes in the array
3. coppying the values of the random indexes to a different array. (this array has twice as little genes, because it is the sperm cell)
The problem that I encounter is making sure that I don't copy an index more then once.
For example, if my original cell's array is
1,0,1,1,1,0,1,0
I don't want it to get the index - 1 - 3 times.
I don't want
1,1,1,1,1,1,0
Know what I mean?
So I tried to do the following:
1. After I copy the value of the random index, I set the value of that index equal to 3.
2. I check, in a while loop, on the next round of the for loop, if the current index of the array is equal to 3.
3. If it is equal to 3, then I set an integer equal to another random value of the array.
4. I check to see if the integer's value is equal to 3 (just in case it chose something that has been chosen already) and if it is, then I use the "continue;" statement to redo this.
5. If the integer's value IS NOT equal to 3, then i set the current index of my new array (the sperm array) equal to the value of the integer.
For some reason this isn't working. When I run the program, it shows me a lot of 3's in the output. In fact, the amount of 3's in the output accumilate as the program goes on (probably because my while loop is not filtering them out of it.)
Here is my code:
public class DivideGenes
    public int badcopy =0;
    boolean[] genes;
    public int[] dgene = new int[250];
    public int tempgene;
    public int integergene[] = new int[501];
    public int geneholder;
    public DivideGenes(boolean[] genes)
        this.genes = genes;
   public int randommath() { //finds a random number
            double tempgene2 = Math.random();
            tempgene2 = tempgene2*100;
            tempgene = (int)tempgene2;
      return tempgene;
    public void randmategenes() //main process
System.out.println("STARTED THE DivideGenes MAIN PROCESS");
      for (int i =0; i <= 500; i++) {
System.out.println("Genes: " + genes[i]);
if (genes[i] == true) {
//converts the boolean array to an integer array
integergene[i] = 1;
else {
integergene[i] = 0;
System.out.println("Intergergene: " + integergene[i]);
for (int i = 0; i < 250; i++) { //creates the sperm cell
while (integergene[i] == 3) {
//this is where the troubles begins
geneholder = integergene[randommath()];
if (geneholder == 3) {
continue;
else {
dgene[i] = geneholder;
break;
dgene[i] = integergene[randommath()];
integergene[tempgene] = 3;
System.out.println("The random gene is " + dgene[i]);
System.out.println("There were " + badcopy + "bad copies");
sorry, its not very well commented. I can't really comment on this , i am afraid that it will look weird.

Thefurly,
If I understood the task correctly, the following code might do it. This is inspiring, please do post similar tasks :)import java.util.*;
class DivideGenes {
     public static final int MAX_GENES = 500;
     private Vector undividedGenes = new Vector(MAX_GENES);
     private int[] dividedGenes = new int[MAX_GENES/2];
     public DivideGenes() {
          startDivision();
     private void startDivision() {
          initGenes();
          divideGenes();
     public void initGenes() {
          Random random = new Random();
          boolean value = false;
          System.out.println("Undivided genes:");
          for(int x = 0; x < MAX_GENES ; x++) {
               value = random.nextBoolean();
               undividedGenes.add(new Integer(value?1:0));
               System.out.print(value?1:0);
     private void divideGenes() {
          Integer nextGene = null;
          int randomIndex = 0;
          int dividedCounter = 0;
          int x = 0;
          System.out.println("\nDivided genes:");
          for(; x < dividedGenes.length; x++) {
               //select a random gene location from the shrinking Vector
               randomIndex = getRandom(0, undividedGenes.size());
               //get the gene. undividedGenes shrinks :), so we'll never get the same one
               nextGene = (Integer)undividedGenes.remove(randomIndex);
               //store the gene's value
               dividedGenes[dividedCounter++] = nextGene.intValue();
          //show divided genes
          for(x = 0; x < dividedGenes.length; x++)
               System.out.print(dividedGenes[x]);
     private static int getRandom(int from, int to) {
          return Math.abs(new Random().nextInt() % to) + from;
     public static void main(String[] args) { new DivideGenes();     }
}Cheers!

Similar Messages

  • My iPod Classic is seen by Windows but not by iTunes.  I have reset it, gone to disk mode and it won't show up in iTunes.  There appears to be music on it in a file called MUSICSAVE.  How can I get this to work with iTunes again?

    My iPod Classic is seen by Windows but not by iTunes.  I have reset it, gone to disk mode and it won't show up in iTunes.  There appears to be music on it in a file called MUSICSAVE.  How can I get this to work with iTunes again?

    1. Update iTunes to the latest version. Plug in your iPod. If iTunes still can't recognize it, then in iTunes in the top left corner click help> run diagnostics. On the box that comes up, check the last two things. Click next and it should identify your iPod.
    2. Click on your windows start menu. Type in "services". Click on it and when it pops up, on the bottom of it click on "standard". Now Scroll down to find "Apple Mobile Device" Right click it when you see it and click on "Start". When it has started, close iTunes and replug in your iPod and it should show up.
    3. Check the USB cable
    4 Verify that Apple Mobile Device Support is installed
    5. Restart the Apple Mobile Device Service and verify that the Apple Mobile Device USB Driver is installed.
    6. If you just want to add some photos, songs and movies from computer to your devices, you can use an iTunes alternative to do the job
    7. Check for third-party software conflicts.
    <Link Edited By Host>

  • I am using Numbers on my iPhone5 and cannot get the app to do a simple (SUM) calculation.  It shows the formula correctly in the cell, but all I get for my long list of numbers to add is 0.  How can I get this to work?

    I am using Numbers on my iPhone5 and cannot get the app to do a simple (SUM) calculation.  It shows the formula correctly in the cell, but all I get for my long list of numbers to add is 0.  How can I get this to work?

    Oaky, at least we got that far.  Next step is to determine if all those "numbers" are really numbers.  Changing the format to "number" doesn't necessarily change the string to a number. The string has to be in the form of a number.  Some may appear to you and me as numbers but will not turn into "numbers" when you change the formatting from Text to Number. Unless you've manually formatted the cells to be right justified, one way to tell if it is text or a number is the justification. Text will be justified to the left, numbers will be justified to the right.
    Here are some that will remain as strings:
    +123
    123 with a space after it.
    .123

  • HT201322 Can't get this to work on iPad A1395 with iOS 6.1.2 - any suggestions?

    Can't get this to work on iPad A1395 with iOS 6.1.2 - any suggestions?

    If you mean hiding or unhiding apps, the article is incorrect since iOS 6 and the accompanying iTunes Store redesign were released. You can at this time only hide and unhide apps through iTunes on your computere.
    Regards.

  • On the fifa 14 iTunes app it won't let me turn on device music, how can I get this to work?

    On the fifa 14 iTunes app it won't let me turn on device music, how can I get this to work?
    I have bought full access to it.

    1. Update iTunes to the latest version. Plug in your iPod. If iTunes still can't recognize it, then in iTunes in the top left corner click help> run diagnostics. On the box that comes up, check the last two things. Click next and it should identify your iPod.
    2. Click on your windows start menu. Type in "services". Click on it and when it pops up, on the bottom of it click on "standard". Now Scroll down to find "Apple Mobile Device" Right click it when you see it and click on "Start". When it has started, close iTunes and replug in your iPod and it should show up.
    3. Check the USB cable
    4 Verify that Apple Mobile Device Support is installed
    5. Restart the Apple Mobile Device Service and verify that the Apple Mobile Device USB Driver is installed.
    6. If you just want to add some photos, songs and movies from computer to your devices, you can use an iTunes alternative to do the job
    7. Check for third-party software conflicts.
    <Link Edited By Host>

  • Negative (to inline a letter or to thin it) offset path does not work in Illus-CC 2014 (when preview is on- nothing happens). How can I get this to work like in previous versions.

    Negative (to inline a letter or to thin it) offset path does not work in Illus-CC 2014 (when preview is on- nothing happens). How can I get this to work like in previous versions.

    Thanks for your quick reply. I tried a number of different values. Usually when I do a negative offset they're very small values, like -.25 or -.5.
    An Update- I took the art work into Ai CS 6 and It still did not work, which is really strange. And I've used it hundreds of times with success in the past. Also I tried it with live type and outlines, ungrouped, un-compounded still could not get it to negative offset.
    Thanks for the help.

  • My laptop has broken and i have been given a new one by apple - this has changed my serial number so my Adobe Ps,Ai etc are not working and say my licence has expired. How can i get this to work?

    My laptop has broken and i have been given a new one by apple - this has changed my serial number so my Adobe Ps,Ai etc are not working and say my licence has expired. How can i get this to work?

    uninstall anything adobe 'migrated' to your new mac, clean and then properly install, Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
    if you need an activation count reset, http://helpx.adobe.com/x-productkb/global/service1.html

  • Email messages from my icloud account update on all my devices showing if they have been read and if a reply has been sent.  This does not happen with my tinyworld (TalkTalk) email account.  Can I (how can I) get this to work with TinyWorld?

    Email messages from my icloud account update on all my devices showing if they have been read and if a reply has been sent.  This does not happen with my tinyworld (TalkTalk) email account.  Can I (how can I) get this to work with TinyWorld?

    You have to look at the email protocol being used.  the Apple email system uses IMAP, does Tinyworld use IMAP or POP?
    Does the email system permit delivery receipts to be requested?
    Just some of the things one needs to determine from the information provided by the email service provider.

  • I have 3 computers and one has the "clear search history" line greyed out. I can't get this to work.

    # Question
    I have 3 computers and one has the "clear search history" line greyed out. I can't get this to work.

    Is Tools > Options > Privacy > History: "Remember search and form history" enabled?
    If that is disabled then there is nothing saved and nothing to delete.<br />
    You still see suggestions in the drop down list if showing suggestions is enabled.
    *http://kb.mozillazine.org/Search_Bar

  • TS1702 My cars 2 app mate app is not working after upgrading from ipad to ipad 2...... synced.... uninstalled and re installed several times as well as wiped ne ipad out and re did the whole proccess several times. how can I get this app working?

    I have installed the cars 2 app mate on a ipad 2 from an ipad 1 synced with itunes account.. all is working except this app. After many times of un installing and re installing aswell as talking to apple tech suport this app is still not working.... its there it just has no function...... how can i get this installed and working, my grandson is autistic and uses this app many hours a day........ it is important for me to get this up and running again for him.......

    (1) So, I found a youtube video showing how to open up my iMac and replace a Disk drive. I opened it. I removed the disk drive. I opened the metal cover of the lid of the disk drive. It was clean and immaculate; so, it destroyed and debunked the dirty drive theory. But, just to make sure I sucked around the optical sensor with a vacuum and gently brushed it with a Q-tip.
    (2) I then watched a you tube video showing how the drive operated (it was a drive supplied with power outside an iMac with a transparent cover unlike the opaque metal cover that we have on our drives). My scientific curiosity started to wonder if somehow the mechanical part (of the electro-mechanical assembly) was locked or jammed. So, I started messing with the arms with the utmost care after watching the video to see if i could move them manually. Yes on some. The main arm that is linked with the drive motor was immovable. The rest I played with a little bit, took great notice in the start of the video to see how the arms looked before inserting a disk. I then put it all back together.
    It works now. My guess is that taking it out and then placing it back in along with the resetting options that others have done was the trick. I believe it is a possibility that the hard drive became locked mechanically in some strange manner after ejecting a DVD in conjunction with the uploading of the new OS. I believe the actual removal, reinstallation, and resetting of the drive put everything back into sync. My computer sits in a climate controlled dust free environment. I knew for a fact that this hard drive was OKAY.

  • Outlook 2007 - Can anyone get this to work?

    Just wondering if anyone had success with this, it's really frustrating that the Oracle connector doesn't work with Outlook 2007.

    I've tried to get this to work on several machine configurations (Office 2007 with and with out Office 2003) using the latest Connector for Outlook on Windows XP and Windows Vista and was still unable to get it to work. I'm 100% convinced that Oracle needs to work on this ASAP and I'm even more astonished and perplexed that Oracle have not provided a solution for their customers. This has pushed me to the point where MSExchange, even Novell are being consider as a permanent alternative. Let's face it, Exchange does seem that they finally got their act together and offers a lot of flexibility for Mobility.
    I've spent about 80+ hours on this and have permanently given up until I hear back from the Oracle developers, who doesn't seem to have a solution readily available to give provide. I'm interested in anyone's comments about their conversations with Oracle.

  • I wanted to watch tv on demands but says this is not HTML5 delivery so how can I get this to work on ipad so I can catch up my tv program any help?

    How can I get tv on demands working on my iPad  as wanted to watch my program but it says HTML5 not supported on this, so any ideas that can help?

    HTML5 is supported on the iPad but I assume that the site that you are going to doesn't yet support it. Does the site have it's own app - here in the UK the TV channels have their own apps, plus there are apps such as TVCatchup.

  • Feeling really stupid...can't get this to work

    Hi All,
    Hoping someone can help me out here. I have a mac mini with 1gig ram. Tiger installed and I am trying to hook up my Yamaha P80 ditial piano to the mini. I am using an M-audio uno cable....midi to USB that my local mac store said would do the trick and get my piano into garageband. But I am not able to get it to work. Software is downloaded and was successful...keyboard is on and working fine just won't record into garageband....have tried using "real intrument" and the only choices I see do not include a piano....the grand piano is in the main track but I can't make it into my piano. Anyone get what I am trying to say and understand what the problem could be. I am so tired of searching and trying to find a similar situation so sorry if it does exist....I feel dumb. The only thing I can think could be a problem is I am running the piano through a stereo receiver so I can play it through speakers....could that be the problem?
    Tammy

    Your piano should work perfectly fine as a midi controller, if you are using the midi out jack on the piano. The problem is that you are using "real instrument", you should be using "software instrument" and choosing a piano there. You cannot use your piano's onboard sound if you are plugging it into the computer through the midi jack. You have to use the Garageband software sounds. If you want to use your Yamaha's onboard sounds you have to go from your audio jack out on the piano, probably the 1/4" jacks, into an interface like a Tascam US-122 or an iMic and then into the computer. Then you can choose "real instrument", and you probably just want to select "basic track-no effects" to get the pure unadulterated sound from your computer.

  • I am running Firefox 4 - when I open a new tab, my recent history shows - how can I get this to work in Firefox 6?

    When opening a new tab, by clicking the + sign, in FF4, recent history and frequented web pages appear. I cannot get this to repeat in later versions of FF - 5 or 6. I like this feature - can I utilize it in FF6? I am running Vista Home Premium 6.06002 SP2 on a Gateway (emachines) T5246 Athlon 64 4200+ 2.2mHz dual core with 2 GB RAM.

    The Ask Toolbar is causing that in the Firefox 3.6.13+ versions. Uninstall that extension.
    There are a couple of places to check for the Ask toolbar:
    * Check the Windows Control panel for the Ask Toolbar - http://about.ask.com/apn/toolbar/docs/default/faq/en/ff/index.html#na4
    * Also check your list of extensions, you may be able to uninstall it from there - https://support.mozilla.com/kb/Uninstalling+add-ons

  • My iphone just was updated yesterday and now my calendars won't synch, how can I get this to work again?

    I just updated my iphone4g and now when synching my calendars will not update. How can I fix this?

    System restore can do that, I recommend to avoid using system restore, it can create problems as well as solve them.
    Try deleting the Firefox installation directory and then re-installing Firefox 3.6
    For 32 bit Windows the default location of the [http://kb.mozillazine.org/Installation_directory installation directory] is C:\Program Files\Mozilla Firefox\
    You can get Firefox 3.6 from http://www.mozilla.com/en-US/firefox/all-older.html

Maybe you are looking for

  • Problem parsing a xml using Jdom

    Hi all, I am reposting it as I was told to format the code and send it again. I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" att

  • My Garageband project crashed, the file lost/damaged! How to recover it?

    Guys, I've been working my garageband project when suddenly the window was closed and the notification asked me to reopen, report or ignore it. This is my second time my project crashed. The first time, I chose 'reopen', and my file reopen. All the m

  • I am transferring my Time Machine to a new hard drive, and it keeps crashing. Why?

    I purchased a 3 TB Western Digital Firewire Drive (it also has USB) to set up as a new Time Machine. I want to use my present backup file. I am not experiencing any problems with my present Time Machine, but the drive is very full. I am following the

  • Entries

    Experts:- if we have doubts, we can ask that , I attended the one of the interview that one ask if we automatic payment programe paying co code, and sednig co code, what are the enteries, suppose if u pay other companies payments, plz tell me entries

  • Help!  contacts disappear when computer is shut down

    Every time I shut down my iMac, my contacts folder completely vanishes. The first time it happened, I didn't know what happened. I rebuilt my address book. Today I had to shut down my computer because I was having a glitch with Safari, and when I reb