-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
实现输出一个十六进制的随机颜色(#af0128a) #170
Labels
Comments
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getColor() {
let result = new Array(6)
let i = 0
let hexMap = ['a', 'b', 'c', 'd', 'e', 'f']
while (i < 6) {
let data = getRandomInt(0, 16)
result[i] = data > 10 ? hexMap[data % 10] : data
i++
}
return `#${result.join('')}`
} |
function randomColor() {
const r = (Math.floor(Math.random() * 255)).toString(16);
const g = (Math.floor(Math.random() * 255)).toString(16);
const b = (Math.floor(Math.random() * 255)).toString(16);
const a = (Math.random()).toString(16).slice(2, 4);
console.log(a);
return `#` + r + g + b + a;
} |
// 实现输出一个十六进制的随机颜色(#af0128a)
let color = '#' + parseInt(Math.random() * 0x1000000).toString(16).padStart(6, '0')
console.log(color); |
var colorStr = '#';
function randomColor() {
var items = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f'];
var index = Math.floor(Math.random()*15);
return items[index];
}
for (let i = 0; i < 6; i++) {
colorStr += randomColor();
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: