Generate Random numbers without using any external functions

后端 未结 9 1013
梦如初夏
梦如初夏 2020-12-08 16:26

This was questions asked in one of the interviews that I recently attended.

As far as I know a random number between two numbers can be generated as follows

9条回答
  •  一个人的身影
    2020-12-08 16:31

    Does System.currentTimeMillis() count as external? You could always get this and calculate mod by some max value:

    int rand = (int)(System.currentTimeMillis()%high)+low;
    

提交回复
热议问题