FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/src/main/java/com/examplehub/utils/RandomUtils.java at master · examplehub/Java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
examplehub
/
Java
Public
Notifications
You must be signed in to change notification settings
Fork
22
Star
26
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
src
/
main
/
java
/
com
/
examplehub
/
utils
/
RandomUtils.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (58 loc) · 1.81 KB
Breadcrumbs
Java
/
src
/
main
/
java
/
com
/
examplehub
/
utils
/
RandomUtils.java
Copy path
File metadata and controls
64 lines (58 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
com
.
examplehub
.
utils
;
import
java
.
util
.
Random
;
public
class
RandomUtils
{
/**
* Generate random int numbers in a range.
*
* @param min the min value of random numbers.
* @param max the max value of random numbers.
* @param count the count of random numbers.
* @return {@code count} random numbers from {@code min} to {@code max} range.
*/
public
static
int
[]
randomInts
(
int
min
,
int
max
,
int
count
) {
if
(
min
>
max
) {
throw
new
IllegalArgumentException
(
"min value must be less than or equals to max"
);
}
int
[]
ints
=
new
int
[
count
];
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
count
; ++
i
) {
ints
[
i
] =
min
+
random
.
nextInt
(
max
-
min
+
1
);
}
return
ints
;
}
/**
* Generate random double numbers in a range.
*
* @param min the min value of random numbers.
* @param max the max value of random numbers.
* @param count the count of random numbers.
* @return {@code count} random numbers from {@code min} to {@code max} range.
*/
public
static
double
[]
randomDoubles
(
double
min
,
double
max
,
int
count
) {
if
(
min
>
max
) {
throw
new
IllegalArgumentException
(
"min value must be less than or equals to max"
);
}
double
[]
floats
=
new
double
[
count
];
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
count
; ++
i
) {
floats
[
i
] =
min
+
random
.
nextFloat
() * (
max
-
min
);
}
return
floats
;
}
/**
* Generate random letters.
*
* @param count the count of random letters.
* @return {@code count} random letters.
*/
public
static
String
randomLetters
(
int
count
) {
int
min
=
0
;
int
max
=
127
;
int
[]
chars
=
randomInts
(
min
,
max
,
count
);
StringBuilder
buffer
=
new
StringBuilder
();
for
(
int
aChar
:
chars
) {
buffer
.
append
((
char
)
aChar
);
}
return
buffer
.
toString
();
}
}
Back
|
FazBrowse Home
|
New Git URL