本文整理汇总了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;
}
示例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]);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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));
}
}
示例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;
}
示例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);
}
}
}
}
示例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]);
}
示例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();
}
}
示例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();
}
}
示例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();
}