@icgio/icg-utils 1.9.3 → 1.9.5

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 +6 -2
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -842,9 +842,13 @@ 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, a, b) => {
846
+ let min = Math.min(a, b)
847
+ let max = Math.max(a, b)
846
848
  let u = 1 - Math.random() // [0,1) -> (0,1]
847
849
  let v = Math.random()
848
850
  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
851
+ let num = mean + z * std_dev
852
+ // Clip to range
853
+ return Math.max(min, Math.min(max, num))
850
854
  }
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.5",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {