我希望在1000到8192000之间得到随机数。随机数应该是1000,2000,3000到8192000。
以下是我尝试但未取得任何成功的代码。
ran.nextInt(8192000 - 1000)%1000;
为了获得1000,2000,3000 ......的数字,我应该改变什么?
答案 0 :(得分:4)
最简单的方法似乎是生成1到8192之间的随机数,然后将其乘以1000:
import numpy as np
import matplotlib.pyplot as plt
class CustomCursor(object):
def __init__(self, axes, col, xlimits, ylimits, **kwargs):
self.items = np.zeros(shape=(len(axes),3), dtype=np.object)
self.col = col
self.focus = 0
i = 0
for ax in axes:
axis = ax
axis.set_gid(i)
lx = ax.axvline(ymin=ylimits[0],ymax=ylimits[1],color=col)
ly = ax.axhline(xmin=xlimits[0],xmax=xlimits[1],color=col)
item = list([axis,lx,ly])
self.items[i] = item
i += 1
def show_xy(self, event):
if event.inaxes:
self.focus = event.inaxes.get_gid()
for ax in self.items[:,0]:
self.gid = ax.get_gid()
for lx in self.items[:,1]:
lx.set_xdata(event.xdata)
if event.inaxes.get_gid() == self.gid:
self.items[self.gid,2].set_ydata(event.ydata)
self.items[self.gid,2].set_visible(True)
plt.draw()
def hide_y(self, event):
for ax in self.items[:,0]:
if self.focus == ax.get_gid():
self.items[self.focus,2].set_visible(False)
if __name__ == '__main__':
fig = plt.figure(facecolor='#07000d')
ax1 = plt.subplot2grid((2,4), (0,0), rowspan=1,colspan=4, axisbg='#aaaaaa')
ax2 = plt.subplot2grid((2,4), (1,0), rowspan=1,colspan=4, axisbg='#aaaaaa')
cc = CustomCursor([ax1,ax2], col='red', xlimits=[0,100], ylimits=[0,100], markersize=30,)
fig.canvas.mpl_connect('motion_notify_event', cc.show_xy)
fig.canvas.mpl_connect('axes_leave_event', cc.hide_y)
plt.tight_layout()
plt.show()
答案 1 :(得分:2)
如果你想要8192000包括试试:
Random random = new Random();
for (int i = 0; i < 10; i++) {
System.out.println((random.nextInt(8192) + 1) * 1000);
}
在这里你得到的值:1000,2000,...,8192000