Skip to content

Add a pseudo-random generator directly into the WASM module #57

@f-aguzzi

Description

@f-aguzzi

Is your feature request related to a problem? Please describe.
The random numbers used in the k-means clustering algorithm require calls to the WASM runtime through the JS bridge, and this slows down the execution. I propose the addition of a xorshift pseudo-random generator within the Rust code as a speed-up.

Describe the solution you'd like
Something like this:

pub struct Xorshift {
    state: u32,
}

impl Xorshift {
    pub fn new(seed: u32) -> Self {
        Xorshift { state: seed }
    }

    pub fn next(&mut self) -> f64 {
        self.state ^= (self.state << 13);
        self.state ^= (self.state >> 17);
        self.state ^= (self.state << 5);
        self.state as f64 / u32::MAX as f64
    }
}

Describe alternatives you've considered
Leaving it as it is. It doesn't really matter.

Additional context
Нет ничего.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions