Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

use thiserror::Error;

#[derive(Error, Debug)]
pub enum RandomGeneratorError {
    #[error("Error generating random bytes: {msg:?}")]
    GeneratorError { msg: String },
}

pub fn generate_u32() -> Result<u32, RandomGeneratorError> {
    let mut buf = [0u8; 4];
    getrandom::getrandom(&mut buf)
        .map_err(|e| RandomGeneratorError::GeneratorError { msg: e.to_string() })?;

    Ok(u32::from_be_bytes(buf))
}