-
Notifications
You must be signed in to change notification settings - Fork 0
/
coupon.java
108 lines (74 loc) · 1.54 KB
/
coupon.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package username;
import java.util.Scanner;
import java.awt.List;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Random;
public class coupon
{
public static void dup(int s)
{
int ran;
int i=0;
int j,k=0;
int cocount = 0;
int ranc = 0;
int count=0;
int[] a=new int[s];
int [] b=new int[s+10];
count=0;
SecureRandom r=new SecureRandom();
for(i =0;i<b.length;i++)
{
ran=r.nextInt();
ranc++;
if(ran==b[i])
{
j=i+1;
Random ru= new Random ();
while(ran>i & ran<j)
ran=ru.nextInt();
b[i]=ran;
}
else
{
b[i]=ran;
}
}
Utility.bublesort(b, s+10);
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
/*System.out.println("enter the range");
num=sc.nextInt();*/
System.out.println("enter the number of coupons to be generated");
int size = sc.nextInt();
coupon.dup(size);
/*for(i=0;i<sort.size();i++)
{
System.out.println(sort.get(i));
}
/*System.out.println(""+ran);
for(j=0;j<a.length;j++)
{
if(ran==a[j] || ran<0 )
{
count++;
}
}
if(count==0 && k<size)
{
a[k++]=ran;
cocount++;
}
}
for(j=0;j<a.length;j++)
{
System.out.println(a[j]);
}
System.out.println("random coupons generated"+ranc);*/
}
}