@icgio/icg-utils 1.9.3 → 1.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/utils.js +4 -2
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -842,9 +842,11 @@ module.exports.sort_keys = (dict) => {
842
842
  return _.fromPairs(_.sortBy(_.toPairs(dict), (e) => e[0]))
843
843
  }
844
844
 
845
- module.exports.random_normal = (mean, std_dev) => {
845
+ module.exports.random_normal_range = (mean, std_dev, min, max) => {
846
846
  let u = 1 - Math.random() // [0,1) -> (0,1]
847
847
  let v = Math.random()
848
848
  let z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v) // Box-Muller Transform
849
- return mean + z * std_dev
849
+ let num = mean + z * std_dev
850
+ // Clip to range
851
+ return Math.max(min, Math.min(max, num))
850
852
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {