当前位置: 首页>>代码示例>>Java>>正文


Java Random.nextInt方法代码示例

本文整理汇总了Java中java.util.Random.nextInt方法的典型用法代码示例。如果您正苦于以下问题:Java Random.nextInt方法的具体用法?Java Random.nextInt怎么用?Java Random.nextInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Random的用法示例。


在下文中一共展示了Random.nextInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStarDirection

import java.util.Random; //导入方法依赖的package包/类
/**
 * 初始化星球运行方向
 */
private int getStarDirection() {
    Random random = new Random();
    int randomInt = random.nextInt(4);
    int direction = 0;
    switch (randomInt) {
        case 0:
            direction = LEFT;
            break;
        case 1:
            direction = RIGHT;
            break;
        case 2:
            direction = TOP;
            break;
        case 3:
            direction = BOTTOM;
            break;
    }
    return direction;
}
 
开发者ID:BittleDragon,项目名称:StarrySkyDemo,代码行数:24,代码来源:StarrySkyView.java

示例2: runAddRemoveSingleThread

import java.util.Random; //导入方法依赖的package包/类
private long runAddRemoveSingleThread(int reps) {
  Random random = new Random();
  int nKeys = keys.size();
  long blah = 0;
  for (int i = 0; i < reps; i++) {
    Integer key = keys.get(random.nextInt(nKeys));
    // This range is [-5, 4] - slight negative bias so we often hit zero, which brings the
    // auto-removal of zeroes into play.
    int delta = random.nextInt(10) - 5;
    blah += delta;
    if (delta >= 0) {
      multiset.add(key, delta);
    } else {
      multiset.remove(key, -delta);
    }
  }
  return blah;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:ConcurrentHashMultisetBenchmark.java

示例3: run

import java.util.Random; //导入方法依赖的package包/类
@Override
protected void run(Context context) throws Exception {
    Document expectedDoc = getExpectedDocument(context);
    int docLen = expectedDoc.getLength();
    if (docLen == 0)
        return; // Nothing to possibly remove
    Random random = context.container().random();
    int length;
    if (REMOVE_CHAR.equals(name())) {
        length = 1;
    } else if (REMOVE_TEXT.equals(name())) {
        Integer maxLength = (Integer) context.getPropertyOrNull(REMOVE_TEXT_MAX_LENGTH);
        if (maxLength == null)
            maxLength = Integer.valueOf(10);
        if (maxLength > docLen)
            maxLength = Integer.valueOf(docLen);
        length = random.nextInt(maxLength) + 1;
    } else {
        throw new IllegalStateException("Unexpected op name=" + name());
    }
    int offset = random.nextInt(docLen - length + 1);
    remove(context, offset, length);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DocumentContentTesting.java

示例4: Crossing

import java.util.Random; //导入方法依赖的package包/类
public Crossing(int p_i45580_1_, Random p_i45580_2_, StructureBoundingBox p_i45580_3_, EnumFacing p_i45580_4_)
{
    super(p_i45580_1_);
    this.coordBaseMode = p_i45580_4_;
    this.field_143013_d = this.getRandomDoor(p_i45580_2_);
    this.boundingBox = p_i45580_3_;
    this.field_74996_b = p_i45580_2_.nextBoolean();
    this.field_74997_c = p_i45580_2_.nextBoolean();
    this.field_74995_d = p_i45580_2_.nextBoolean();
    this.field_74999_h = p_i45580_2_.nextInt(3) > 0;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:12,代码来源:StructureStrongholdPieces.java

示例5: nextBytes

import java.util.Random; //导入方法依赖的package包/类
/**
 * Same as java.util.Random.nextBytes except this one we dont have to
 * allocate a new byte array
 * 
 * @param into
 *            byte[]
 * @param offset
 *            int
 * @param length
 *            int
 * @param r
 *            Random
 */
public static void nextBytes(byte[] into, int offset, int length, Random r) {
	int numRequested = length;
	int numGot = 0, rnd = 0;
	while (true) {
		for (int i = 0; i < BYTES_PER_INT; i++) {
			if (numGot == numRequested)
				return;
			rnd = (i == 0 ? r.nextInt() : rnd >> BITS_PER_BYTE);
			into[offset + numGot] = (byte) rnd;
			numGot++;
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:27,代码来源:UUIDGenerator.java

示例6: shuffleArray

import java.util.Random; //导入方法依赖的package包/类
private static void shuffleArray(int[] array)
{
    int index;
    Random random = new Random();
    for (int i = array.length - 1; i > 0; i--)
    {
        index = random.nextInt(i + 1);
        if (index != i)
        {
            array[index] ^= array[i];
            array[i] ^= array[index];
            array[index] ^= array[i];
        }
    }
}
 
开发者ID:ndleyton,项目名称:OneTwo,代码行数:16,代码来源:TouchDisplayView.java

示例7: randPermutation

import java.util.Random; //导入方法依赖的package包/类
/**
 * Generate random permutation given an array
 * @param array
 * @return
 */
public static final int[] randPermutation(int[] array) {
	Random r = new Random();
	int randNum;
	for (int i = 0; i < array.length; i++) {
		randNum = i + r.nextInt(array.length-i);
		swap(array, i, randNum);
	}
	return array;
}
 
开发者ID:ChangWeiTan,项目名称:FastWWSearch,代码行数:15,代码来源:Tools.java

示例8: random

import java.util.Random; //导入方法依赖的package包/类
public static String random() {
    Random generator = new Random();
    StringBuilder randomStringBuilder = new StringBuilder();
    int randomLength = generator.nextInt(20);
    char tempChar;
    for (int i = 0; i < randomLength; i++){
        tempChar = (char) (generator.nextInt(96) + 32);
        randomStringBuilder.append(tempChar);
    }
    return randomStringBuilder.toString();
}
 
开发者ID:IOSD,项目名称:YFHR_Android_App,代码行数:12,代码来源:SettingsActivity.java

示例9: createListOfRandomWeaponsForLoot

import java.util.Random; //导入方法依赖的package包/类
private void createListOfRandomWeaponsForLoot() {
    Random rnd = new Random();
    int maxLoot = 3 + rnd.nextInt(7);

    for (int i = 0; i < maxLoot; i++) {
        this.possibleLoot.add(new Axe(rnd.nextInt(50), rnd.nextInt(50)));
    }
}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:9,代码来源:Dummy.java

示例10: renderNextTick

import java.util.Random; //导入方法依赖的package包/类
public void renderNextTick(){
    if(!fall()){
        Random random = new Random();
        Brick[] enlargedField = new Brick[field.length+1];
        java.lang.System.arraycopy(field,0,enlargedField,0,enlargedField.length);
        enlargedField[enlargedField.length-1] = currentBrick.copy();
        field = enlargedField;
        currentBrick = nextBrick;
        nextBrick = bricks[random.nextInt(bricks.length)];
    }
}
 
开发者ID:konsultaner,项目名称:word-clock-raspberry-pi-zero-neopixels,代码行数:12,代码来源:Tetris.java

示例11: Straight

import java.util.Random; //导入方法依赖的package包/类
public Straight(int p_i45573_1_, Random p_i45573_2_, StructureBoundingBox p_i45573_3_, EnumFacing p_i45573_4_)
{
    super(p_i45573_1_);
    this.coordBaseMode = p_i45573_4_;
    this.field_143013_d = this.getRandomDoor(p_i45573_2_);
    this.boundingBox = p_i45573_3_;
    this.expandsX = p_i45573_2_.nextInt(2) == 0;
    this.expandsZ = p_i45573_2_.nextInt(2) == 0;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:10,代码来源:StructureStrongholdPieces.java

示例12: generateTree

import java.util.Random; //导入方法依赖的package包/类
@Override
public boolean generateTree(World w, Random rand, BlockPos pos) {
	filler.leaf=leaf;
	// Check light levels
	if(w.getLight(pos)<7){
		return false;
	}
	// Check height of trunk
	int h = 3+rand.nextInt(height);
	for(int y = 0; y<h; y++){
		if(!checkBlockAt(w,pos.add(0,y,0))){
			return false;
		}
	}
	for(int y = 0; y < h; y++){
		fill(w,pos.add(0,y,0));
	}
	for(int branch = 0; branch < 5; branch++){
		float incx = rand.nextFloat()-.5f;
		float incz = rand.nextFloat()-.5f;
		float incy = rand.nextFloat()*0.5f + 0.5f;
		float x=0,y=0,z=0;
		for(int bc = 0; bc < 5; bc++){
			x+=incx; y+=incy; z+=incz;
			BlockPos p = pos.add(x, y+h, z);
			fill(w,p);
			filler.fillLeaves(w, p, rand);
		}
	}
	return true;
}
 
开发者ID:trigg,项目名称:Firma,代码行数:32,代码来源:TreeFir.java

示例13: onForwardShortMessageRequest

import java.util.Random; //导入方法依赖的package包/类
@Override
public void onForwardShortMessageRequest(ForwardShortMessageRequest ind) {
    if (!isStarted)
        return;

    MAPDialogSms curDialog = ind.getMAPDialog();
    long invokeId = ind.getInvokeId();
    SM_RP_DA da = ind.getSM_RP_DA();
    SM_RP_OA oa = ind.getSM_RP_OA();
    SmsSignalInfo si = ind.getSM_RP_UI();

    if (da.getIMSI() != null || da.getLMSI() != null) { // mt message
        this.onMtRequest(da, oa, si, curDialog);

        try {
            MtFSMReaction mtFSMReaction = this.testerHost.getConfigurationData().getTestSmsClientConfigurationData().getMtFSMReaction();

            Random rnd = new Random();
            if (this.testerHost.getConfigurationData().getTestSmsClientConfigurationData().isReturn20PersDeliveryErrors()) {
                int n = rnd.nextInt(5);
                if (n == 0) {
                    n = rnd.nextInt(5);
                    mtFSMReaction = new MtFSMReaction(n + 2);
                } else {
                    mtFSMReaction = new MtFSMReaction(MtFSMReaction.VAL_RETURN_SUCCESS);
                }
            }

            if (mtFSMReaction.intValue() == MtFSMReaction.VAL_RETURN_SUCCESS) {
                curDialog.addForwardShortMessageResponse(invokeId);
                this.countMtFsmResp++;

                if (!this.testerHost.getConfigurationData().getTestSmsClientConfigurationData().isOneNotificationFor100Dialogs()) {
                    this.testerHost.sendNotif(SOURCE_NAME, "Sent: mtResp", "", Level.DEBUG);
                }

                if (this.testerHost.getConfigurationData().getTestSmsClientConfigurationData().isContinueDialog())
                    this.needSendSend = true;
                else
                    this.needSendClose = true;
            } else {
                sendMtError(curDialog, invokeId, mtFSMReaction);
                this.needSendClose = true;
            }

        } catch (MAPException e) {
            this.testerHost.sendNotif(SOURCE_NAME, "Exception when invoking addMtForwardShortMessageResponse : " + e.getMessage(), e, Level.ERROR);
        }
    }
}
 
开发者ID:RestComm,项目名称:phone-simulator,代码行数:51,代码来源:TestSmsClientMan.java

示例14: generatePieceFromSmallDoor

import java.util.Random; //导入方法依赖的package包/类
private static StructureStrongholdPieces.Stronghold generatePieceFromSmallDoor(StructureStrongholdPieces.Stairs2 p_175955_0_, List<StructureComponent> p_175955_1_, Random p_175955_2_, int p_175955_3_, int p_175955_4_, int p_175955_5_, EnumFacing p_175955_6_, int p_175955_7_)
{
    if (!canAddStructurePieces())
    {
        return null;
    }
    else
    {
        if (strongComponentType != null)
        {
            StructureStrongholdPieces.Stronghold structurestrongholdpieces$stronghold = findAndCreatePieceFactory(strongComponentType, p_175955_1_, p_175955_2_, p_175955_3_, p_175955_4_, p_175955_5_, p_175955_6_, p_175955_7_);
            strongComponentType = null;

            if (structurestrongholdpieces$stronghold != null)
            {
                return structurestrongholdpieces$stronghold;
            }
        }

        int j = 0;

        while (j < 5)
        {
            ++j;
            int i = p_175955_2_.nextInt(totalWeight);

            for (StructureStrongholdPieces.PieceWeight structurestrongholdpieces$pieceweight : structurePieceList)
            {
                i -= structurestrongholdpieces$pieceweight.pieceWeight;

                if (i < 0)
                {
                    if (!structurestrongholdpieces$pieceweight.canSpawnMoreStructuresOfType(p_175955_7_) || structurestrongholdpieces$pieceweight == p_175955_0_.strongholdPieceWeight)
                    {
                        break;
                    }

                    StructureStrongholdPieces.Stronghold structurestrongholdpieces$stronghold1 = findAndCreatePieceFactory(structurestrongholdpieces$pieceweight.pieceClass, p_175955_1_, p_175955_2_, p_175955_3_, p_175955_4_, p_175955_5_, p_175955_6_, p_175955_7_);

                    if (structurestrongholdpieces$stronghold1 != null)
                    {
                        ++structurestrongholdpieces$pieceweight.instancesSpawned;
                        p_175955_0_.strongholdPieceWeight = structurestrongholdpieces$pieceweight;

                        if (!structurestrongholdpieces$pieceweight.canSpawnMoreStructures())
                        {
                            structurePieceList.remove(structurestrongholdpieces$pieceweight);
                        }

                        return structurestrongholdpieces$stronghold1;
                    }
                }
            }
        }

        StructureBoundingBox structureboundingbox = StructureStrongholdPieces.Corridor.findPieceBox(p_175955_1_, p_175955_2_, p_175955_3_, p_175955_4_, p_175955_5_, p_175955_6_);

        if (structureboundingbox != null && structureboundingbox.minY > 1)
        {
            return new StructureStrongholdPieces.Corridor(p_175955_7_, p_175955_2_, structureboundingbox, p_175955_6_);
        }
        else
        {
            return null;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:68,代码来源:StructureStrongholdPieces.java

示例15: generate

import java.util.Random; //导入方法依赖的package包/类
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    while (worldIn.isAirBlock(position) && position.getY() > 2)
    {
        position = position.down();
    }

    if (worldIn.getBlockState(position).getBlock() != Blocks.snow)
    {
        return false;
    }
    else
    {
        int i = rand.nextInt(this.basePathWidth - 2) + 2;
        int j = 1;

        for (int k = position.getX() - i; k <= position.getX() + i; ++k)
        {
            for (int l = position.getZ() - i; l <= position.getZ() + i; ++l)
            {
                int i1 = k - position.getX();
                int j1 = l - position.getZ();

                if (i1 * i1 + j1 * j1 <= i * i)
                {
                    for (int k1 = position.getY() - j; k1 <= position.getY() + j; ++k1)
                    {
                        BlockPos blockpos = new BlockPos(k, k1, l);
                        Block block = worldIn.getBlockState(blockpos).getBlock();

                        if (block == Blocks.dirt || block == Blocks.snow || block == Blocks.ice)
                        {
                            worldIn.setBlockState(blockpos, this.block.getDefaultState(), 2);
                        }
                    }
                }
            }
        }

        return true;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:43,代码来源:WorldGenIcePath.java


注:本文中的java.util.Random.nextInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。