应用场景:我根据任意用户id、群id,生成固定一个数值,便于我给该用户、群组给头像。
1 function imgNum(id, num) { 2 let arr = id.split(""), 3 sum = 0; 4 arr.forEach(val => sum += val.charCodeAt()); 5 return sum % num 6 } 7 imgNum("quroqfehfrk-3-4-5whr", 20); 8 //6 9 imgNum("2quroqfehfrk-3-4-5whr", 20); 10 //16 11 imgNum("3quroqfehfrk-3-4-5whr", 20); 12 //17 13 imgNum("9quroqfehfrk-3-4-5whr", 20);
原文地址:https://www.cnblogs.com/qtx-/p/11135506.html
时间: 2024-10-29 07:13:11