Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* output
- x list:
- min: 150
- max: 649
- avg: 399.57069
- bucket 0 [150.0, 199.9]: 9978 (10.0%)
- bucket 1 [199.9, 249.8]: 9863 (9.9%)
- bucket 2 [249.8, 299.7]: 10173 (10.2%)
- bucket 3 [299.7, 349.6]: 10101 (10.1%)
- bucket 4 [349.6, 399.5]: 10010 (10.0%)
- bucket 5 [399.5, 449.4]: 9876 (9.9%)
- bucket 6 [449.4, 499.3]: 10039 (10.0%)
- bucket 7 [499.3, 549.2]: 9817 (9.8%)
- bucket 8 [549.2, 599.1]: 10153 (10.2%)
- bucket 9 [599.1, 649.0]: 9801 (9.8%)
- y list:
- min: 10
- max: 789
- avg: 398.78173
- bucket 0 [10.0 , 87.9 ]: 10052 (10.1%)
- bucket 1 [87.9 , 165.8]: 9993 (10.0%)
- bucket 2 [165.8, 243.7]: 10103 (10.1%)
- bucket 3 [243.7, 321.6]: 10034 (10.0%)
- bucket 4 [321.6, 399.5]: 9943 (9.9%)
- bucket 5 [399.5, 477.4]: 10139 (10.1%)
- bucket 6 [477.4, 555.3]: 9926 (9.9%)
- bucket 7 [555.3, 633.2]: 9769 (9.8%)
- bucket 8 [633.2, 711.1]: 9985 (10.0%)
- bucket 9 [711.1, 789.0]: 9930 (9.9%)
- done
- */
- // -----------------------------------------------
- // groovy script
- int getRandomNumber(int min, int max) {
- new Random().nextInt(max - min) + min
- }
- def num = 100_000
- def xList = (0..<num).collect { getRandomNumber(150, 800 - 150) }
- def yList = (0..<num).collect { getRandomNumber(10, 800 - 10) }
- def buckets = 10
- [[xList, 'x list'], [yList, 'y list']].each { list, name ->
- println "${name}:"
- def min = list.min()
- def max = list.max()
- println " min: ${min}"
- println " max: ${max}"
- println " avg: ${list.average()}"
- def bucketSize = (max - min) / buckets
- buckets.times { bucketNum ->
- def bucketMin = list.min() + bucketSize * bucketNum
- def bucketMax = list.min() + bucketSize * (bucketNum + 1)
- def bucketCount = list.findAll { it >= bucketMin && it < bucketMax }.size()
- def bucketMinStr = bucketMin.round(1).toString().padRight(5)
- def bucketMaxStr = bucketMax.round(1).toString().padRight(5)
- def pcnt = (bucketCount / list.size() * 100).round(1)
- println " bucket ${bucketNum} [${bucketMinStr}, ${bucketMaxStr}]: ${bucketCount} (${pcnt}%)"
- }
- 2.times { println() }
- }
- println 'done'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement