Skip to content
On this page

splitNumRandom

根据给定的总数和位数得到固定位数的随机值的数组

Demo

入参:splitNumRandom(20, 6)
结果:[ 3, 2, 11, 2, 1, 1 ]
总数:20

Usage

ts
<script setup lang="ts">
import { ref } from 'vue'
import { splitNumRandom } from '@morehook/utils'

const randomArr = ref(splitNumRandom(20, 6))

function again() {
  randomArr.value = splitNumRandom(20, 6)
}
</script>

Type Declarations

typescript
/**
 * 根据给定的总数和位数得到固定位数的随机值的数组
 *
 * ps: splitNumRandom(10, 3) => [1, 5, 4]
 * @param total 总数
 * @param n 切割成多少位
 * @return 固定位数,但是值是随机的数组
 */
export declare function splitNumRandom(total: number, n: number): number[]

Source

SourceDemoDocs