[Sorry if my grammar is screwed up, i've suddenly been in a rush, will come back and edit this later]
What are you trying to achieve here? Describe the problem not the solution.
You will be surprised that the problem that drove me to this is client server socket programming.
To summarise I send and receive image files and string data successfully (?) The question marks is because without changing the code between runs it blocks at the server with a success rate of just about approx 30%. That means 70% of the time it blocks. After a lot of hard work I found nothing else improved the situation until I change the outputstream object to be different from the previous one. Then the non-blocking success rate jumped to ~80%
The success rate needs to be 100% though. I could easily always start with zero but it may surprise you - when I restart the server it blocks because it has a memory of the a previous outputstream object
So one way is to write the previous output number to a file and read it at the start so it can be avoided, but i only want to do this as a last resort. Using RGN is my first choice, if it could work the way I described originally (it would be a much simpler solution) because if I choose a very large number for 'total' in the code below, chances are that the player would never reach that number even when they exit and restart the game
Random rand = new Random();
n = rand.nextInt(((total-1) - 0) + 1) + 0;
.......
.......
.......
OutputStream outps[];
outps = new OutputStream[total];
if(n>=total) n=0;
outps[n] = sock.getOutputStream();
outps[n] = sock.getOutputStream();
outps[n].write(mybytearray,0,mybytearray.length); // send file
outps[n].flush();
I'm not sure what gave you the impression that a random number generator would do incremental numbering,
I think you misunderstood me. That I was hoping for non repeating generation didn't mean I expect the randomly generated numbers to be incremental like n, n+1, n+2...
The random number generator will be freed when the program exits, so if you want to maintain its progress you'll need to somehow serialize its state.
In that case May be I will have to go by my second option of saving to file before exit and reading from file at the start to overcome the socket blocking problem