-3

我想要指定范围内的四个不同数字,但我得到了一些数字和一些日期。

此应用程序是这些选择的测试应用程序

Random rn = new Random(); 
int rangetp = maximumb - minimumb + 1; 
randomNums = rn.nextInt(rangetp) + minimumb; 

Random rn1 = new Random(); 
int rangetp1 = maximumb - minimumb + 1; 
randomNums1 = rn1.nextInt(rangetp1) + minimumb; 

Random rn2 = new Random(); 
int rangetp2 = maximumb - minimumb + 1; 
randomNums2= rn2.nextInt(rangetp2) + minimumb; 

Random rn3 = new Random(); 
int rangetp3 = maximumb - minimumb + 1; 
randomNums3 = rn3.nextInt(rangetp3) + minimumb; 

SQLiteDatabase db = veridepo.getReadableDatabase();
cursor = db.rawQuery(
    "SELECT yabanci, turkce, biliyorum
    FROM tablomm
    WHERE id = " + randomNums + "" + sorsunmu + "", null);

cursor1 = db.rawQuery(
    "SELECT yabanci, turkce, biliyorum 
    FROM tablomm 
    WHERE id = " + randomNums1 + "" + sorsunmu + "", null); 

cursor2 = db.rawQuery(
    "SELECT yabanci, turkce, biliyorum 
    FROM tablomm 
    WHERE id = " + randomNums2 + "" + sorsunmu + "", null); 

cursor3 = db.rawQuery(
    "SELECT yabanci, turkce, biliyorum 
    FROM tablomm 
    WHERE id = " + randomNums3 + "" + sorsunmu + "", null); 
4

1 回答 1

3

您只需要一个随机对象而不是 4 个!

Random rn = new Random(); 
int rangetp = maximumb - minimumb + 1; 
randomNums = rn.nextInt(rangetp) + minimumb; 

int rangetp1 = maximumb - minimumb + 1; 
randomNums1 = rn.nextInt(rangetp1) + minimumb; 

int rangetp2 = maximumb - minimumb + 1; 
randomNums2= rn.nextInt(rangetp2) + minimumb; 

int rangetp3 = maximumb - minimumb + 1; 
randomNums3 = rn.nextInt(rangetp3) + minimumb; 

阅读有关 Random 的文档: https ://developer.android.com/reference/java/util/Random.html

这是一个关于随机数的java“问题”以及如何实现更随机的方式来获取随机数。

于 2013-03-10T11:21:33.240 回答