mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-27 04:54:21 +01:00
refactor: use getrandom
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -737,8 +737,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -997,6 +999,7 @@ dependencies = [
|
||||
"cfg_block",
|
||||
"criterion",
|
||||
"fallible-iterator 0.3.0",
|
||||
"getrandom",
|
||||
"io-uring",
|
||||
"libc",
|
||||
"log",
|
||||
@@ -1005,7 +1008,6 @@ dependencies = [
|
||||
"ordered-multimap",
|
||||
"polling",
|
||||
"pprof",
|
||||
"rand",
|
||||
"regex",
|
||||
"rstest",
|
||||
"rusqlite",
|
||||
|
||||
@@ -38,7 +38,7 @@ ordered-multimap = "0.7.1"
|
||||
sieve-cache = "0.1.4"
|
||||
sqlite3-parser = "0.11.0"
|
||||
thiserror = "1.0.61"
|
||||
rand = "0.8.5"
|
||||
getrandom = { version = "0.2.15", features = ["js"] }
|
||||
regex = "1.10.5"
|
||||
|
||||
[target.'cfg(not(target_family = "windows"))'.dev-dependencies]
|
||||
|
||||
@@ -357,9 +357,8 @@ pub fn translate_expr(
|
||||
}
|
||||
SingleRowFunc::Random => {
|
||||
if args.is_some() {
|
||||
anyhow::bail!("Parse error: random function withargumentst");
|
||||
anyhow::bail!("Parse error: random function with arguments");
|
||||
}
|
||||
dbg!("random args", &args);
|
||||
let regs = program.alloc_register();
|
||||
|
||||
program.emit_insn(Insn::Function {
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::schema::Table;
|
||||
use crate::types::{AggContext, Cursor, CursorResult, OwnedRecord, OwnedValue, Record};
|
||||
|
||||
use anyhow::Result;
|
||||
use rand::Rng;
|
||||
use regex::Regex;
|
||||
use std::borrow::BorrowMut;
|
||||
use std::cell::RefCell;
|
||||
@@ -1867,8 +1866,9 @@ fn exec_abs(reg: &OwnedValue) -> Option<OwnedValue> {
|
||||
}
|
||||
|
||||
fn exec_random() -> OwnedValue {
|
||||
let mut rng = rand::thread_rng();
|
||||
let random_number: i64 = rng.gen();
|
||||
let mut buf = [0u8; 8];
|
||||
getrandom::getrandom(&mut buf).unwrap();
|
||||
let random_number = i64::from_ne_bytes(buf);
|
||||
OwnedValue::Integer(random_number)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user