mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 02:31:45 +02:00
Update to using math/rand/v2
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"kitty"
|
"kitty"
|
||||||
"math"
|
"math"
|
||||||
not_rand "math/rand"
|
not_rand "math/rand/v2"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"kitty/tools/cli"
|
"kitty/tools/cli"
|
||||||
@@ -114,16 +113,11 @@ func benchmark_data(description string, data string, opts Options) (duration tim
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var rand_src = sync.OnceValue(func() *rand.Rand {
|
|
||||||
return rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
||||||
})
|
|
||||||
|
|
||||||
func random_string_of_bytes(n int, alphabet string) string {
|
func random_string_of_bytes(n int, alphabet string) string {
|
||||||
b := make([]byte, n)
|
b := make([]byte, n)
|
||||||
al := len(alphabet)
|
al := len(alphabet)
|
||||||
src := rand_src()
|
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
b[i] = alphabet[src.Intn(al)]
|
b[i] = alphabet[rand.IntN(al)]
|
||||||
}
|
}
|
||||||
return utils.UnsafeBytesToString(b)
|
return utils.UnsafeBytesToString(b)
|
||||||
}
|
}
|
||||||
@@ -158,13 +152,12 @@ func unicode() (r result, err error) {
|
|||||||
func ascii_with_csi() (r result, err error) {
|
func ascii_with_csi() (r result, err error) {
|
||||||
const sz = 1024*1024 + 17
|
const sz = 1024*1024 + 17
|
||||||
out := make([]byte, 0, sz+48)
|
out := make([]byte, 0, sz+48)
|
||||||
src := rand_src()
|
|
||||||
chunk := ""
|
chunk := ""
|
||||||
for len(out) < sz {
|
for len(out) < sz {
|
||||||
q := src.Intn(100)
|
q := rand.IntN(100)
|
||||||
switch {
|
switch {
|
||||||
case (q < 10):
|
case (q < 10):
|
||||||
chunk = random_string_of_bytes(src.Intn(72)+1, ascii_printable)
|
chunk = random_string_of_bytes(rand.IntN(72)+1, ascii_printable)
|
||||||
case (10 <= q && q < 30):
|
case (10 <= q && q < 30):
|
||||||
chunk = "\x1b[m\x1b[?1h\x1b[H"
|
chunk = "\x1b[m\x1b[?1h\x1b[H"
|
||||||
case (30 <= q && q < 40):
|
case (30 <= q && q < 40):
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
not_rand "math/rand"
|
not_rand "math/rand/v2"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
@@ -137,7 +137,7 @@ var CacheDir = sync.OnceValue(func() (cache_dir string) {
|
|||||||
}
|
}
|
||||||
candidate = filepath.Join(Expanduser(candidate), "kitty")
|
candidate = filepath.Join(Expanduser(candidate), "kitty")
|
||||||
}
|
}
|
||||||
os.MkdirAll(candidate, 0o755)
|
_ = os.MkdirAll(candidate, 0o755)
|
||||||
return candidate
|
return candidate
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user