Here is what my code looks like stripped down as much as possible:

```
    float delay = (float)5000;
        long startTime = System.nanoTime();
        int elapsed = 0;
        for (int i = 0; i < 20; i++) {
            elapsed = (int) ((System.nanoTime() - startTime) / 1000000);
//          System.out.println("Elapsed: " + elapsed);
            float range = delay * 0.4f;
            float randomNum = (float)(Math.random() * range - (delay * 0.2f));
            if (elapsed > (delay + randomNum)) {
                System.out.println("Random Num: " + randomNum);
                startTime = System.nanoTime();
            } else {
                i--;
                continue;
            }
        }

```

As you can see I'm looping 20 times and printing out a random number after 5 seconds (5000 milliseconds). This is what the output looks like:

[![enter image description here](https://i.stack.imgur.com/OQc2f.png)](https://i.stack.imgur.com/OQc2f.png)

As you can see, all of the outputs are VERY close to -1000. I'm trying to generate a random float from -1000 to 1000, but they all seem to be around -1000. So, I checked to make sure the actual random number generator is working, using this code:

```
    float delay = (float)5000;
        long startTime = System.nanoTime();
        int elapsed = 0;
        for (int i = 0; i < 20; i++) {
            elapsed = (int) ((System.nanoTime() - startTime) / 1000000);
//          System.out.println("Elapsed: " + elapsed);
            float range = delay * 0.4f;
            float randomNum = (float)(Math.random() * range - (delay * 0.2f));                  
            System.out.println("Random Num: " + randomNum);
            startTime = System.nanoTime();
        }

```

Basically I took elapsed out of the equation and just printed the random numbers without the if statement. This is the output I got:

[![enter image description here](https://i.stack.imgur.com/U2XsV.png)](https://i.stack.imgur.com/U2XsV.png)

In this example, I got very random output, exactly like you would expect. However, once you add elapsed back into the equation like in the first set of code, the output turns back to -999 with some random decimal places.

Even more interesting is that if you put a print statement right above the if statement and right after `randomNum` is assigned a value, you get these outputs:

[![enter image description here](https://i.stack.imgur.com/1N5yD.png)](https://i.stack.imgur.com/1N5yD.png)

Once again, the numbers are random. It seems like for some reason in the first example code with the elapsed part of the code put in, the `randomNum` variable changes right after the if statement is called. Why does this happen?