国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - How to generate random auto-incrementing IDs
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-05-16 13:01:25
0
2
591

I want to use the auto-incremented id in URI to locate resources, but I don’t want the auto-incremented id to be used every time< code>+1, but I hope it is a random number as id, but this id is proportional.
What I think of so far One solution is to use timestamps. Is there any other solution?

Please indicate the programming language when answering

PHP中文網(wǎng)
PHP中文網(wǎng)

認(rèn)證0級(jí)講師

reply all(2)
淡淡煙草味

JavaScript

01

Timestamp

let id = + new Date(); 

Another possible approach

var R = (function(){
    var base = 0
      , inc  = 2;  
      
    // base 是基數(shù), _inc 是增量 
    function config(_base, _inc){
        base = _base; 
        inc = _inc; 
    }
    
    function randGenerator(){
        var pre = base; 
        base += inc; 
        return pre + (Math.random() * inc); 
    }
    
    return {
        rand: randGenerator,
        config: config
    }
})(); 

R.config(0, 2); 
R.rand(); // 0 ~ 2 中的隨機(jī)數(shù)
R.rand(); // 2 ~ 4 中的隨機(jī)數(shù) 

uuid

https://www.npmjs.com/package...

Use uuidV1

劉奇

Generate a random number that does not repeat. Use

?srand() - Seeds a random number generator
?getrandmax() - Displays the largest possible value of a random number
?mt_rand() - Generates better random numbers
These three functions.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template