简体   繁体   English

随机唯一编号,例如IP地址mysql

[英]Random unique number like IP address mysql

I'm making an android game which is made with a hacking theme, and I want to generate a random and unique IP address-style user ID (example xxx.xxx.xx.xx) 我正在制作一个以黑客主题为主题的android游戏,我想生成一个随机且唯一的IP地址样式的用户ID(例如xxx.xxx.xx.xx)

At the moment I know how to generate a unique ID, but it is just incremented from 1 and up. 目前,我知道如何生成唯一的ID,但是它只是从1开始递增。

I don't know if it is maybe only possible through php? 我不知道是否只有通过php才可能? Or even the android app's side? 甚至是Android应用程序的一面?

Any help would be greatly appreciated! 任何帮助将不胜感激!

Try this on Android app side, 在Android应用程序端尝试此操作,

Random random = new Random();
return random.nextInt(256) + "." + random.nextInt(256) + "." + random.nextInt(256) + "." + random.nextInt(256);

See this SO thread. 看到这个 SO线程。

Edit : To generate random numbers without repeatations, see this thread. 编辑:要生成不重复的随机数,请参阅线程。 You will have to modify it for your need though. 但是,您将不得不根据需要对其进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM