import java.net.*;
import java.io.*;
import java.util.Scanner;
public class Rand
{
public static void main(String[] args) throws Exception
{
System.out.printf("Integer Generator\n(c) First Name Last Name, 2014 All Rights Reserved\nNumbers Supplied by https://www.random.org/, This Connection is SSL protected by COMODO.\nGenerated numbers will be stored in output.txt\nWrite the quantities: \n");
Scanner in=new Scanner(System.in);
int p=in.nextInt(), m, n;
while(true)
{
System.out.println("Write the Maximum number: ");
m=in.nextInt();
System.out.println("Write the Minimum number: ");
n=in.nextInt();
if(n<m) break;
System.out.println("Maximum is smaller than Minimum, Try again.");
}
PrintWriter writer=new PrintWriter("output.txt");
String[] inputLine=new String[p];
boolean b=false;
int i=0;
while(i<p)
{
b=false;
HttpURLConnection c=(HttpURLConnection)new URL("https://www.random.org/integers/?num=1&min="+n+"&max="+m+"&col=1&base=10&format=plain&rnd=new").openConnection();
c.setRequestProperty("Accept-Charset", "UTF-8");
c.setDoInput(true);
c.setDoOutput(false);
c.connect();
BufferedReader out=new BufferedReader(new InputStreamReader(c.getInputStream()));
inputLine[i]=out.readLine();
c.disconnect();
for(int j=i-1; j>=0; j--)
{
if(i==0) break;
if(inputLine[j]==inputLine[i])
{
inputLine[i]=null;
b=true;
break;
}
}
if(b) continue;
writer.println(inputLine[i]);
i++;
}
writer.close();
}
}
I programmed this code as a mini beginner project(Forgive me if this has an easy solution, I'm a 7th grader, please don't give me deductions)
I made it to give a sequence of numbers randomly without the same numbers repeating.
ex) 1 3 5 6 4 2 if quantity is 6, maximum is 6, minimum is 1.
However, it comes out like this: 4 1 6 4 4 1
What's wrong with this? Please give me an explanation.