我正在尝试在原始数据类型 short 的范围(-32768、32767)上生成随机整数.java Random 对象只生成正数.我将如何在该间隔上随机创建数字?谢谢.
I am trying to generate random integers over the range (-32768, 32767) of the primitive data type short. The java Random object only generates positive numbers. How would I go about randomly creating numbers on that interval? Thanks.
你随机对 (0, 32767+32768)
然后减去 32768
You random on (0, 32767+32768)
then subtract by 32768
这篇关于如何在Java中生成随机正数和负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!