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 · JavaCimcoz/Java · GitHub
JavaCimcoz
/
Java
Public
forked from
examplehub/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
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
46 lines (42 loc) · 1.39 KB
Breadcrumbs
Java
/
src
/
main
/
java
/
com
/
examplehub
/
utils
/
RandomUtils.java
Copy path
File metadata and controls
46 lines (42 loc) · 1.39 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
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
] =
random
.
nextInt
(
max
-
min
+
1
) +
min
;
}
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
;
}
}
Back
|
FazBrowse Home
|
New Git URL