创建唯一id

## onion.createRandom ### 1. 功能 使用模板引擎时, 需要用到唯一id进行 CRUD 操作时 ### 2. 使用场景 ![image.png](https://cos.easydoc.net/27100029/files/kb8qo1ud.png) ![image.png](https://cos.easydoc.net/27100029/files/kb8qooli.png) ### 3. 如何使用 ```js onion.createRandom (n) ``` n 为所需 id 的字符串数量 ### 4. api定义 ``` javascript onion.createRandom = function (n) { var result = ''; var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; var lens = n || 20 for (var i = 0; i < lens; i++) { var pos = Math.round(Math.random() * (arr.length - 1)); result += arr[pos]; } return result; }; ```