Skip to content

Commit e4b14e5

Browse files
rustyconoverclaude
andcommitted
Replace boost::random with std::random for WASM compatibility
- Remove boost::random dependency, use std::<random> and custom implementations for distributions not in the standard library (beta, laplace, logistic, pareto, rayleigh) - Replace custom thread-local RNG with DuckDB's RandomEngine via RngAdapter (thread-safe, supports setseed() for reproducibility) - Fix data race: acquire RandomEngine::lock before seeding - Fix bug in DistributionCallUnaryUnary: args.data[2] -> args.data[1] - Fix missing cauchy distribution registration - Fix uniform_int to use boost::math::uniform_distribution<double> - Fix quantile return types for discrete distributions - Restore sampling for logistic, pareto, rayleigh distributions - Remove stale forward declarations from utils.hpp - Add BOOST_MATH_STANDALONE compile definition - Add comprehensive test coverage for all 22 distributions - Document setseed() reproducibility in docs/README.md - Add .cache/ and vcpkg/ to .gitignore Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e761518 commit e4b14e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4368
-256
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ duckdb_unittest_tempdir/
66
testext
77
test/python/__pycache__/
88
.Rhistory
9+
.cache/
10+
vcpkg/

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ file(GLOB DISTRIBUTION_SOURCES "src/distribution_*.cpp")
2121

2222
set(EXTENSION_SOURCES
2323
src/stochastic_extension.cpp
24-
src/rng_utils.cpp
2524
src/query_farm_telemetry.cpp
2625
${DISTRIBUTION_SOURCES}
2726
)
@@ -31,6 +30,8 @@ build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
3130

3231
target_link_libraries(${EXTENSION_NAME} Boost::math)
3332
target_link_libraries(${LOADABLE_EXTENSION_NAME} Boost::math)
33+
target_compile_definitions(${EXTENSION_NAME} PRIVATE BOOST_MATH_STANDALONE)
34+
target_compile_definitions(${LOADABLE_EXTENSION_NAME} PRIVATE BOOST_MATH_STANDALONE)
3435

3536
install(
3637
TARGETS ${EXTENSION_NAME}

docs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ Below are the parameters for each supported distribution. Use these as arguments
224224
| `min` | Lower bound (integer) |
225225
| `max` | Upper bound (integer, must be ≥ min) |
226226

227+
## Reproducible Sampling
228+
229+
All `dist_*_sample()` functions use DuckDB's built-in random engine. You can control the random seed for reproducible results using DuckDB's `setseed()` function:
230+
231+
```sql
232+
-- Set seed for reproducible results
233+
SELECT setseed(0.42);
234+
235+
-- These will produce the same values every time with the same seed
236+
SELECT dist_normal_sample(0.0, 1.0) FROM generate_series(1, 5);
237+
```
238+
239+
Without calling `setseed()`, each session produces different random values.
240+
227241
## Usage Examples
228242

229243
### Normal Distribution

0 commit comments

Comments
 (0)