每天都有古怪的单线解决方案。
数组中的值是完全随机的,所以当你使用这个 sn-ps 时,它会有所不同。
小写随机字符的数组(长度为 10)
Array.apply(null, Array(10)).map(function() { return String.fromCharCode(Math.floor(Math.random() * (123 - 97) + 97)); })
['k'、'a'、'x'、'y'、'n'、'w'、'm'、'q'、'b'、'j']
一个从 0 到 99 的随机整数数组(长度为 10)
Array.apply(null, Array(10)).map(function() { return Math.floor(Math.random() * 100 % 100); })
[86、77、83、27、79、96、67、75、52、21]
一个数组随机日期(从 10 年前到现在)
Array.apply(null, Array(10)).map(function() { return new Date((new Date()).getFullYear() - Math.floor(Math.random() * 10), Math.floor(Math.random() * 12), Math.floor(Math.random() * 29) )})
[ 2008-08-22T21:00:00.000Z, 2007-07-17T21:00:00.000Z,
2015-05-05T21:00:00.000Z, 2011-06-14T21:00:00.000Z,
2009-07-23T21:00:00.000Z, 2009-11-13T22:00:00.000Z,
2010-05-09T21:00:00.000Z, 2008-01-05T22:00:00.000Z,
2016-05-06T21:00:00.000Z, 2014-08-06T21:00:00.000Z]
一个数组(长度为 10)随机字符串
Array.apply(null, Array(10)).map(function() { return Array.apply(null, Array(Math.floor(Math.random() * 10 + 3))).map(function() { return String.fromCharCode(Math.floor(Math.random() * (123 - 97) + 97)); }).join('') });
['cubjjhaph',
“宝马”,
'alhob',
'ceud',
'tnyullyn',
'vpkdlarhnf',
'hvg',
'阿拉祖尔',
'爵士',
'cyx']
您可以在这里找到其他有用的东西https://github.com/setivolkylany/nodejs-utils/blob/master/utils/faker.js