[Javascript] use Math.random() to generate random color and string

export const randomColor = () => {
  return "#" + Math.random().toString(16).substring(2, 8).padEnd(6, '0')
}

export const randomString = (len: number) => {
  return len <= 11 ? Math.random().toString(36).substring(2, 2+len).padEnd(len, '0') : randomString(11) + randomString(len-11)
}

 

posted @   Zhentiw  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2022-09-03 [Typescript] 14. Easy - Parameters
2022-09-03 [Typescript] 13. Easy - Unshift
2022-09-03 [Typescript] 12. Easy - Push
2022-09-03 [Typescript] 11. Medium - Equal
2021-09-03 [Cloud Architect] 4. Introduction to Design for Cost, Performance, & Scalability
2019-09-03 [Dart] Capture and Handle Data Sequences with Streams in Dart
2019-09-03 [Javascript] Run asynchronous functions in sequence using reduce
点击右上角即可分享
微信分享提示