當前位置: 首頁>>代碼示例>>Java>>正文


Java Random.nextFloat方法代碼示例

本文整理匯總了Java中java.util.Random.nextFloat方法的典型用法代碼示例。如果您正苦於以下問題:Java Random.nextFloat方法的具體用法?Java Random.nextFloat怎麽用?Java Random.nextFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Random的用法示例。


在下文中一共展示了Random.nextFloat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: scaleCodeHeapSize

import java.util.Random; //導入方法依賴的package包/類
/**
 * Returns {@code unscaledSize} value scaled by a random factor from
 * range (1, 2). If {@code unscaledSize} is not 0, then this
 * method will return value that won't be equal to {@code unscaledSize}.
 *
 * @param unscaledSize The value to be scaled.
 * @return {@code unscaledSize} value scaled by a factor from range (1, 2).
 */
private static long scaleCodeHeapSize(long unscaledSize) {
    Random random = Utils.getRandomInstance();

    long scaledSize = unscaledSize;
    while (scaledSize == unscaledSize && unscaledSize != 0) {
        float scale = 1.0f + random.nextFloat();
        scaledSize = (long) Math.ceil(scale * unscaledSize);
    }
    return scaledSize;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:JVMStartupRunner.java

示例2: randomDisplayTick

import java.util.Random; //導入方法依賴的package包/類
public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (this.isRepeaterPowered)
    {
        EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
        double d0 = (double)((float)pos.getX() + 0.5F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
        double d1 = (double)((float)pos.getY() + 0.4F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
        double d2 = (double)((float)pos.getZ() + 0.5F) + (double)(rand.nextFloat() - 0.5F) * 0.2D;
        float f = -5.0F;

        if (rand.nextBoolean())
        {
            f = (float)(((Integer)state.getValue(DELAY)).intValue() * 2 - 1);
        }

        f = f / 16.0F;
        double d3 = (double)(f * (float)enumfacing.getFrontOffsetX());
        double d4 = (double)(f * (float)enumfacing.getFrontOffsetZ());
        worldIn.spawnParticle(EnumParticleTypes.REDSTONE, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:22,代碼來源:BlockRedstoneRepeater.java

示例3: generatePassword

import java.util.Random; //導入方法依賴的package包/類
@Override
public String generatePassword(String id) {
  if (id == null || id.isEmpty()) {
    return null;
  }
  String password = null;
  // Take the first 4 letters of id
  if (id.length() <= 4) {
    password = id;
  } else {
    password = id.substring(0, 4);
  }
  // Generate a 3 digit random number
  Random r = new Random();
  r.setSeed(System.currentTimeMillis());
  float f = r.nextFloat();
  password += String.valueOf((int) ((f * 1000.0f) % 1000));
  return password;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:20,代碼來源:AuthenticationServiceImpl.java

示例4: generate

import java.util.Random; //導入方法依賴的package包/類
@Override
public boolean generate(World worldIn, Random rand, BlockPos position) {
	if(size.equals(BlockPos.ORIGIN) && rand.nextFloat() < this.chance)
	{
		worldIn.setBlockState(position, Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.HORIZONTALS[rand.nextInt(4)]), 3);
		((TileEntityChest)worldIn.getTileEntity(position)).setLootTable(lootTable, rand.nextLong());
		return false;
	}
	for(int x = 0; x < size.getX(); x++)
		for(int z = 0; z < size.getZ(); z++)
			if(rand.nextFloat() < this.chance)
			{
				BlockPos blockpos = new BlockPos(position.add(x, 0, z));
				boolean flag = false;
				for(EnumFacing facing : EnumFacing.HORIZONTALS)
					if(worldIn.getBlockState(blockpos.offset(facing)).getBlock() == Blocks.CHEST)
						flag = true;
				if(flag || !worldIn.isAirBlock(blockpos))
					continue;
				if(setBlock)
					worldIn.setBlockState(blockpos, Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.HORIZONTALS[rand.nextInt(4)]), 3);
				((TileEntityChest)worldIn.getTileEntity(blockpos)).setLootTable(lootTable, rand.nextLong());
			}
	return false;
}
 
開發者ID:kenijey,項目名稱:harshencastle,代碼行數:26,代碼來源:ChestGenerator.java

示例5: nextFloat

import java.util.Random; //導入方法依賴的package包/類
/**
 * Returns a pseudo-random, uniformly distributed double value between
 * origin (inclusively) and bound (exclusively).
 *
 * @param origin lower bound for generated float value (inclusively)
 * @param bound upper bound for generated float value (exclusively)
 * @param random the random engine used for creating the random number.
 * @return a random float greater than or equal to {@code origin} and less
 *         than to {@code bound}
 * @throws IllegalArgumentException if {@code origin} is greater than or
 *         equal to {@code bound}
 * @throws NullPointerException if the given {@code random}
 *         engine is {@code null}.
 */
public static float nextFloat(
	final float origin, final float bound,
	final Random random
) {
	if (!(origin < bound)) {
		throw new IllegalArgumentException(format(
			"min >= max: %f >= %f.", origin, bound
		));
	}

	float value = random.nextFloat();
	if (origin < bound) {
		value = value*(bound - origin) + origin;
		if (value >= bound) {
			value = intBitsToFloat(floatToIntBits(bound) - 1);
		}
	}

	return value;
}
 
開發者ID:jenetics,項目名稱:prngine,代碼行數:35,代碼來源:PRNG.java

示例6: getDownloadFile

import java.util.Random; //導入方法依賴的package包/類
private File getDownloadFile(Uri targetUri) throws IOException {
    String fileName;
    Random random = new Random();
    float v = random.nextFloat();
    try {
        fileName = Util.getMD5("nat/transfer/download" + System.currentTimeMillis()) + v;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        fileName = "nat/transfer/download" + System.currentTimeMillis() + v;
    }
    File parentFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + targetUri.getPath());
    if (!parentFile.exists()) parentFile.mkdirs();

    return new File(parentFile, fileName);
}
 
開發者ID:natjs,項目名稱:nat-network-transfer,代碼行數:16,代碼來源:TransferModule.java

示例7: updateMushroom

import java.util.Random; //導入方法依賴的package包/類
public void updateMushroom() {
    if (cam.position.x - cam.viewportWidth / 2 > mushroom.getPosObs().x + mushroom.getWidth()) {
        Random rand = new Random();
        float fluctuation = rand.nextFloat();
        float distance = (fluctuation * 2500) + GameTutorial.WIDTH;
        mushroom.reposition(mushroom.getPosObs().x + distance, 70);
        mushroomIsTouched = false;
    }
}
 
開發者ID:MissionBit,項目名稱:summer17-android,代碼行數:10,代碼來源:Level2.java

示例8: updatePoops

import java.util.Random; //導入方法依賴的package包/類
public void updatePoops(){
    if (cam.position.x - cam.viewportWidth / 2 > poop.getPosObs().x + poop.getWidth()) {
        Random rand = new Random();
        float fluctuation = rand.nextFloat();
        float distance = (fluctuation * 1500) + GameTutorial.WIDTH;
        poop.reposition(poop.getPosObs().x + distance, 60);
        poopIsTouched = false;
    }
}
 
開發者ID:MissionBit,項目名稱:summer17-android,代碼行數:10,代碼來源:Level4.java

示例9: runGenerator

import java.util.Random; //導入方法依賴的package包/類
private void runGenerator(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chancesPerChunk, float chancesToSpawn, int minHeight, int maxHeight) 
{
	int heightDiff = maxHeight - minHeight + 1;
    for (int i = 0; i < chancesPerChunk; i ++) 
    	if(random.nextFloat() < chancesToSpawn)
    	{
    		int x = chunkX * 16 + random.nextInt(16);
	        int y = minHeight + random.nextInt(heightDiff);
	        int z = chunkZ * 16 + random.nextInt(16);
	        generator.generate(world, random, new BlockPos(x, y, z));
    	} 
}
 
開發者ID:kenijey,項目名稱:harshencastle,代碼行數:13,代碼來源:WorldGen.java

示例10: genFloatArray

import java.util.Random; //導入方法依賴的package包/類
public static float[] genFloatArray(int dim) {
  Random random = new Random(System.currentTimeMillis());
  float[] array = new float[dim];
  for (int i = 0; i < dim; i++)
    array[i] = random.nextFloat();

  return array;
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:9,代碼來源:Utils.java

示例11: randomDisplayTick

import java.util.Random; //導入方法依賴的package包/類
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random)
{
    TileEntity te = world.getTileEntity(pos);
    if (te != null && te instanceof TileEntityIronFurnace)
    {
        TileEntityIronFurnace tef = (TileEntityIronFurnace) te;
        if (tef.isActive())
        {
            byte facing = tef.getFacing();
            float x = pos.getX() + 0.5F;
            float y = pos.getY() + 0.0F + random.nextFloat() * 6.0F / 16.0F;
            float z = pos.getZ() + 0.5F;
            float var10 = 0.52F;
            float var11 = random.nextFloat() * 0.6F - 0.3F;

            if (facing == 4)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x - var10, y, z + var11, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x - var10, y, z + var11, 0.0D, 0.0D, 0.0D);
            } else if (facing == 5)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x + var10, y, z + var11, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x + var10, y, z + var11, 0.0D, 0.0D, 0.0D);
            } else if (facing == 2)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x + var11, y, z - var10, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x + var11, y, z - var10, 0.0D, 0.0D, 0.0D);
            } else if (facing == 3)
            {
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x + var11, y, z + var10, 0.0D, 0.0D, 0.0D);
                world.spawnParticle(EnumParticleTypes.FLAME, x + var11, y, z + var10, 0.0D, 0.0D, 0.0D);
            }
        }
    }
}
 
開發者ID:cubex2,項目名稱:morefurnaces,代碼行數:38,代碼來源:BlockMoreFurnaces.java

示例12: randomDisplayTick

import java.util.Random; //導入方法依賴的package包/類
public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    double d0 = (double)((float)pos.getX() + rand.nextFloat());
    double d1 = (double)((float)pos.getY() + 0.8F);
    double d2 = (double)((float)pos.getZ() + rand.nextFloat());
    double d3 = 0.0D;
    double d4 = 0.0D;
    double d5 = 0.0D;
    worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5, new int[0]);
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:11,代碼來源:BlockEndPortal.java

示例13: selectBlocks

import java.util.Random; //導入方法依賴的package包/類
public void selectBlocks(Random rand, int x, int y, int z, boolean p_75062_5_)
{
    if (rand.nextFloat() < 0.4F)
    {
        this.blockstate = Blocks.COBBLESTONE.getDefaultState();
    }
    else
    {
        this.blockstate = Blocks.MOSSY_COBBLESTONE.getDefaultState();
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:12,代碼來源:ComponentScatteredFeaturePieces.java

示例14: doRenderLayer

import java.util.Random; //導入方法依賴的package包/類
public void doRenderLayer(EntityDragon entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale)
{
    if (entitylivingbaseIn.deathTicks > 0)
    {
        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer vertexbuffer = tessellator.getBuffer();
        RenderHelper.disableStandardItemLighting();
        float f = ((float)entitylivingbaseIn.deathTicks + partialTicks) / 200.0F;
        float f1 = 0.0F;

        if (f > 0.8F)
        {
            f1 = (f - 0.8F) / 0.2F;
        }

        Random random = new Random(432L);
        GlStateManager.disableTexture2D();
        GlStateManager.shadeModel(7425);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
        GlStateManager.disableAlpha();
        GlStateManager.enableCull();
        GlStateManager.depthMask(false);
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.0F, -1.0F, -2.0F);

        for (int i = 0; (float)i < (f + f * f) / 2.0F * 60.0F; ++i)
        {
            GlStateManager.rotate(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 0.0F, 0.0F, 1.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(random.nextFloat() * 360.0F + f * 90.0F, 0.0F, 0.0F, 1.0F);
            float f2 = random.nextFloat() * 20.0F + 5.0F + f1 * 10.0F;
            float f3 = random.nextFloat() * 2.0F + 1.0F + f1 * 2.0F;
            vertexbuffer.begin(6, DefaultVertexFormats.POSITION_COLOR);
            vertexbuffer.pos(0.0D, 0.0D, 0.0D).color(255, 255, 255, (int)(255.0F * (1.0F - f1))).endVertex();
            vertexbuffer.pos(-0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
            vertexbuffer.pos(0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
            vertexbuffer.pos(0.0D, (double)f2, (double)(1.0F * f3)).color(255, 0, 255, 0).endVertex();
            vertexbuffer.pos(-0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
            tessellator.draw();
        }

        GlStateManager.popMatrix();
        GlStateManager.depthMask(true);
        GlStateManager.disableCull();
        GlStateManager.disableBlend();
        GlStateManager.shadeModel(7424);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.enableTexture2D();
        GlStateManager.enableAlpha();
        RenderHelper.enableStandardItemLighting();
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:57,代碼來源:LayerEnderDragonDeath.java

示例15: renderStars

import java.util.Random; //導入方法依賴的package包/類
private void renderStars()
{
    final Random rand = new Random(10842L);
    final Tessellator var2 = Tessellator.instance;
    var2.startDrawingQuads();

    for (int starIndex = 0; starIndex < (ConfigManagerCore.moreStars ? 35000 : 6000); ++starIndex)
    {
        double var4 = rand.nextFloat() * 2.0F - 1.0F;
        double var6 = rand.nextFloat() * 2.0F - 1.0F;
        double var8 = rand.nextFloat() * 2.0F - 1.0F;
        final double var10 = 0.15F + rand.nextFloat() * 0.1F;
        double var12 = var4 * var4 + var6 * var6 + var8 * var8;

        if (var12 < 1.0D && var12 > 0.01D)
        {
            var12 = 1.0D / Math.sqrt(var12);
            var4 *= var12;
            var6 *= var12;
            var8 *= var12;
            final double var14 = var4 * (ConfigManagerCore.moreStars ? rand.nextDouble() * 150D + 130D : 100.0D);
            final double var16 = var6 * (ConfigManagerCore.moreStars ? rand.nextDouble() * 150D + 130D : 100.0D);
            final double var18 = var8 * (ConfigManagerCore.moreStars ? rand.nextDouble() * 150D + 130D : 100.0D);
            final double var20 = Math.atan2(var4, var8);
            final double var22 = Math.sin(var20);
            final double var24 = Math.cos(var20);
            final double var26 = Math.atan2(Math.sqrt(var4 * var4 + var8 * var8), var6);
            final double var28 = Math.sin(var26);
            final double var30 = Math.cos(var26);
            final double var32 = rand.nextDouble() * Math.PI * 2.0D;
            final double var34 = Math.sin(var32);
            final double var36 = Math.cos(var32);

            for (int var38 = 0; var38 < 4; ++var38)
            {
                final double var39 = 0.0D;
                final double var41 = ((var38 & 2) - 1) * var10;
                final double var43 = ((var38 + 1 & 2) - 1) * var10;
                final double var47 = var41 * var36 - var43 * var34;
                final double var49 = var43 * var36 + var41 * var34;
                final double var53 = var47 * var28 + var39 * var30;
                final double var55 = var39 * var28 - var47 * var30;
                final double var57 = var55 * var22 - var49 * var24;
                final double var61 = var49 * var22 + var55 * var24;
                var2.addVertex(var14 + var57, var16 + var53, var18 + var61);
            }
        }
    }

    var2.draw();
}
 
開發者ID:BlesseNtumble,項目名稱:TRAPPIST-1,代碼行數:52,代碼來源:SkyProviderTrappistOneC.java


注:本文中的java.util.Random.nextFloat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。