Advertisement
Guest User

Untitled

a guest
Nov 26th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. const std = @import("std");
  2.  
  3. const Normal = struct {
  4. mean: f64,
  5. standard_deviation: f64,
  6.  
  7. pub fn sample(normal: Normal, r: *std.rand.Random) f64 {
  8. return normal.mean + r.floatNorm(f64) * normal.standard_deviation;
  9. }
  10. };
  11.  
  12. test "Normal" {
  13. var r = std.rand.Xoroshiro128.init(42);
  14. const normal = Normal{ .mean = 0, .standard_deviation = 1 };
  15. const actual = normal.sample(&(r.random));
  16. const expected = 1.103529993107505;
  17. std.testing.expectEqual(actual, expected);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement