Skip to content

Commit 1a5e963

Browse files
author
sx
committed
adjust category
1 parent 0ca3d8c commit 1a5e963

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ base_convert()
137137
is_nan()
138138
```
139139

140+
### CSPRNG Functions
141+
```php
142+
random_bytes()
143+
random_int()
144+
```
145+
140146
### Directory/Filesystem Functions
141147
```php
142148
stat()

php.go

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,33 +1310,6 @@ func Rand(min, max int) int {
13101310
return r.Intn(max+1-min) + min
13111311
}
13121312

1313-
// RandomBytes random_bytes()
1314-
func RandomBytes(length int) ([]byte, error) {
1315-
bs := make([]byte, length)
1316-
_, err := crand.Read(bs)
1317-
if err != nil {
1318-
return nil, err
1319-
}
1320-
1321-
return bs, nil
1322-
}
1323-
1324-
// RandomInt random_int()
1325-
func RandomInt(min, max int) (int, error) {
1326-
if min > max {
1327-
panic("argument #1 must be less than or equal to argument #2")
1328-
}
1329-
1330-
if min == max {
1331-
return min, nil
1332-
}
1333-
nb, err := crand.Int(crand.Reader, big.NewInt(int64(max+1-min)))
1334-
if err != nil {
1335-
return 0, err
1336-
}
1337-
return int(nb.Int64()) + min, nil
1338-
}
1339-
13401313
// Round round()
13411314
func Round(value float64, precision int) float64 {
13421315
p := math.Pow10(precision)
@@ -1458,6 +1431,35 @@ func IsNan(val float64) bool {
14581431
return math.IsNaN(val)
14591432
}
14601433

1434+
//////////// CSPRNG Functions ////////////
1435+
1436+
// RandomBytes random_bytes()
1437+
func RandomBytes(length int) ([]byte, error) {
1438+
bs := make([]byte, length)
1439+
_, err := crand.Read(bs)
1440+
if err != nil {
1441+
return nil, err
1442+
}
1443+
1444+
return bs, nil
1445+
}
1446+
1447+
// RandomInt random_int()
1448+
func RandomInt(min, max int) (int, error) {
1449+
if min > max {
1450+
panic("argument #1 must be less than or equal to argument #2")
1451+
}
1452+
1453+
if min == max {
1454+
return min, nil
1455+
}
1456+
nb, err := crand.Int(crand.Reader, big.NewInt(int64(max+1-min)))
1457+
if err != nil {
1458+
return 0, err
1459+
}
1460+
return int(nb.Int64()) + min, nil
1461+
}
1462+
14611463
//////////// Directory/Filesystem Functions ////////////
14621464

14631465
// Stat stat()
@@ -2105,7 +2107,7 @@ func VersionCompare(version1, version2, operator string) bool {
21052107
}
21062108
} else if !(p1[0] >= '0' && p1[0] <= '9') && !(p2[0] >= '0' && p2[0] <= '9') { // all digit
21072109
compare = special(p1, p2)
2108-
} else { // part is digit
2110+
} else { // part is digit
21092111
if p1[0] >= '0' && p1[0] <= '9' { // is digit
21102112
compare = special("#N#", p2)
21112113
} else {

0 commit comments

Comments
 (0)