Java 类java.util.Random 实例源码
项目:AmenEye
文件:SplashActivity.java
private void setImgBackGround() {
String[] images = getResources().getStringArray(R.array.splash_background);
int position = new Random().nextInt(images.length - 1) % (images.length);
Glide.with(this)
.load(images[position])
.into(mImgBackGround);
String path = SpUtil.getString(this, "path");
Glide.with(this)
.load(path)
.asBitmap()
.error(R.drawable.def_avatar)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
mCircleImageView.setImageBitmap(resource);
}
});
//设置图像的透明度
AlphaAnimation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(800);
mCircleImageView.startAnimation(animation);
animation.setAnimationListener(this);
}
项目:jtk
文件:AnnotationTest.java
@Test
public void testConstructorsAllEqual() {
Random r = new Random();
int x = (int)(r.nextFloat()*100);
int y = (int)(r.nextFloat()*100);
int z = (int)(r.nextFloat()*100);
Point3 p = new Point3(x,y,z);
Annotation[] ans = new Annotation[4];
ans[0] = new Annotation(x,y,z);
ans[1] = new Annotation(p);
ans[2] = new Annotation(x,y,z,"");
ans[3] = new Annotation(p,"");
for (int i=0; i<ans.length; ++i) {
assertEquals(Color.WHITE,ans[i].getColor());
assertEquals(p,ans[i].getLocation());
assertEquals("",ans[i].getText());
assertEquals(Annotation.Alignment.EAST,ans[i].getAlignment());
assertEquals(
new Font("SansSerif",Font.PLAIN,18),ans[i].getFont());
}
}
项目:CustomWorldGen
文件:Particle.java
protected Particle(World worldIn, double posXIn, double posYIn, double posZIn)
{
this.boundingBox = EMPTY_AABB;
this.width = 0.6F;
this.height = 1.8F;
this.rand = new Random();
this.particleAlpha = 1.0F;
this.worldObj = worldIn;
this.setSize(0.2F, 0.2F);
this.setPosition(posXIn, posYIn, posZIn);
this.prevPosX = posXIn;
this.prevPosY = posYIn;
this.prevPosZ = posZIn;
this.particleRed = 1.0F;
this.particleGreen = 1.0F;
this.particleBlue = 1.0F;
this.particleTextureJitterX = this.rand.nextFloat() * 3.0F;
this.particleTextureJitterY = this.rand.nextFloat() * 3.0F;
this.particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
this.particleMaxAge = (int)(4.0F / (this.rand.nextFloat() * 0.9F + 0.1F));
this.particleAge = 0;
this.canCollide = true;
}
项目:logistimo-web-service
文件:AuthenticationServiceImpl.java
@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;
}
项目:DecompiledMinecraft
文件:StructureMineshaftPieces.java
protected boolean generateChestContents(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, List<WeightedRandomChestContent> listIn, int max)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (boundingBoxIn.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.air)
{
int i = rand.nextBoolean() ? 1 : 0;
worldIn.setBlockState(blockpos, Blocks.rail.getStateFromMeta(this.getMetadataWithOffset(Blocks.rail, i)), 2);
EntityMinecartChest entityminecartchest = new EntityMinecartChest(worldIn, (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.5F), (double)((float)blockpos.getZ() + 0.5F));
WeightedRandomChestContent.generateChestContents(rand, listIn, entityminecartchest, max);
worldIn.spawnEntityInWorld(entityminecartchest);
return true;
}
else
{
return false;
}
}
项目:BaseClient
文件:WorldGenMegaPineTree.java
public void func_180711_a(World worldIn, Random p_180711_2_, BlockPos p_180711_3_)
{
this.func_175933_b(worldIn, p_180711_3_.west().north());
this.func_175933_b(worldIn, p_180711_3_.east(2).north());
this.func_175933_b(worldIn, p_180711_3_.west().south(2));
this.func_175933_b(worldIn, p_180711_3_.east(2).south(2));
for (int i = 0; i < 5; ++i)
{
int j = p_180711_2_.nextInt(64);
int k = j % 8;
int l = j / 8;
if (k == 0 || k == 7 || l == 0 || l == 7)
{
this.func_175933_b(worldIn, p_180711_3_.add(-3 + k, 0, -3 + l));
}
}
}
项目:BaseClient
文件:WorldGenBigTree.java
public boolean generate(World worldIn, Random rand, BlockPos position)
{
this.world = worldIn;
this.basePos = position;
this.rand = new Random(rand.nextLong());
if (this.heightLimit == 0)
{
this.heightLimit = 5 + this.rand.nextInt(this.heightLimitLimit);
}
if (!this.validTreeLocation())
{
return false;
}
else
{
this.generateLeafNodeList();
this.generateLeaves();
this.generateTrunk();
this.generateLeafNodeBases();
return true;
}
}
项目:ibench
文件:SourceFDGenerator.java
@Override
public void generateScenario(MappingScenario scenario,Configuration configuration) throws Exception
{
Random _generator = configuration.getRandomGenerator();
Map<String, Map<String,FD>> fds = new HashMap<String, Map<String,FD>> ();
if (log.isDebugEnabled()) {log.debug("Attempting to Generate Source FDs");};
// create PK FDs R(A,B,C) if A is key then add A -> B,C
if (configuration.getParam(ParameterName.PrimaryKeyFDs) == 1) {
if (log.isDebugEnabled()) {log.debug("Generating PK FDs for those Relations with PKs");};
generatePKFDs(scenario, fds);
}
if (configuration.getParam(Constants.ParameterName.SourceFDPerc) > 0) {
if (log.isDebugEnabled()) {log.debug("Generating Random FDs as SourceFDPerc > 0");};
generateRandomFDs(scenario, configuration, _generator, fds);
}
}
项目:BaseClient
文件:StructureVillagePieces.java
public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
if (this.field_143015_k < 0)
{
this.field_143015_k = this.getAverageGroundLevel(worldIn, structureBoundingBoxIn);
if (this.field_143015_k < 0)
{
return true;
}
this.boundingBox.offset(0, this.field_143015_k - this.boundingBox.maxY + 4 - 1, 0);
}
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 2, 3, 1, Blocks.air.getDefaultState(), Blocks.air.getDefaultState(), false);
this.setBlockState(worldIn, Blocks.oak_fence.getDefaultState(), 1, 0, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.oak_fence.getDefaultState(), 1, 1, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.oak_fence.getDefaultState(), 1, 2, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.wool.getStateFromMeta(EnumDyeColor.WHITE.getDyeDamage()), 1, 3, 0, structureBoundingBoxIn);
boolean flag = this.coordBaseMode == EnumFacing.EAST || this.coordBaseMode == EnumFacing.NORTH;
this.setBlockState(worldIn, Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, this.coordBaseMode.rotateY()), flag ? 2 : 0, 3, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, this.coordBaseMode), 1, 3, 1, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, this.coordBaseMode.rotateYCCW()), flag ? 0 : 2, 3, 0, structureBoundingBoxIn);
this.setBlockState(worldIn, Blocks.torch.getDefaultState().withProperty(BlockTorch.FACING, this.coordBaseMode.getOpposite()), 1, 3, -1, structureBoundingBoxIn);
return true;
}
项目:morpheus-core
文件:SortingTests.java
@Test(dataProvider = "order")
public void testLocalDateRowSortByKeys(boolean ascending, boolean parallel) {
final Random random = new Random();
final Array<LocalDate> rowKeys = Range.ofLocalDates("2000-01-01", "2010-01-01").toArray().shuffle(2);
final Array<String> colKeys = Array.of("A", "B", "C", "D");
final DataFrame<LocalDate,String> frame = DataFrame.ofDoubles(rowKeys, colKeys).applyDoubles(v -> random.nextDouble());
frame.out().print();
final DataFrame<LocalDate,String> sorted = parallel ? frame.rows().parallel().sort(ascending) : frame.rows().sequential().sort(ascending);
sorted.out().print();
sorted.rows().forEach(row -> {
if (row.ordinal() > 0) {
final LocalDate key0 = sorted.rows().key(row.ordinal()-1);
final LocalDate key1 = sorted.rows().key(row.ordinal());
if (ascending) {
Assert.assertTrue(key0.compareTo(key1) < 0, "Keys are in ascending order");
} else {
Assert.assertTrue(key0.compareTo(key1) > 0, "Keys are in descending order");
}
}
});
}
项目:Proyecto-DASI
文件:MazeDecoratorImplementation.java
private void initRNGs()
{
// Initialise a RNG for this scene:
long seed = 0;
if (this.mazeParams.getSeed() == null || this.mazeParams.getSeed().equals("random"))
seed = System.currentTimeMillis();
else
seed = Long.parseLong(this.mazeParams.getSeed());
this.pathrand = new Random(seed);
this.blockrand = new Random(seed);
// Should we initialise a separate RNG for the block types?
if (this.mazeParams.getMaterialSeed() != null)
{
long bseed = 0;
if (this.mazeParams.getMaterialSeed().equals("random"))
bseed = System.currentTimeMillis();
else
bseed = Long.parseLong(this.mazeParams.getMaterialSeed());
this.blockrand = new Random(bseed);
}
}
项目:devops-cstack
文件:VolumeControllerTestIT.java
/**
* Cannot create two volumes with same name
*
* @throws Exception
*/
@Test()
public void createTwoVolumesWithError()
throws Exception {
VolumeResource volumeResource = new VolumeResource();
volumeResource.setName("shared" + new Random().nextInt(100000));
ResultActions resultActions = createVolume(volumeResource);
resultActions.andExpect(status().isCreated());
// Convert the result to pojo
volumeResource = getVolumeResource(mapper, resultActions);
// Try to create a second volume but error
resultActions = createVolume(volumeResource);
resultActions.andExpect(status().is4xxClientError());
// delete the volume
deleteVolume(volumeResource.getId(), HttpStatus.NO_CONTENT);
}
项目:CustomWorldGen
文件:LootTable.java
public void fillInventory(IInventory inventory, Random rand, LootContext context)
{
List<ItemStack> list = this.generateLootForPools(rand, context);
List<Integer> list1 = this.getEmptySlotsRandomized(inventory, rand);
this.shuffleItems(list, list1.size(), rand);
for (ItemStack itemstack : list)
{
if (list1.isEmpty())
{
LOGGER.warn("Tried to over-fill a container");
return;
}
if (itemstack == null)
{
inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), (ItemStack)null);
}
else
{
inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), itemstack);
}
}
}
项目:hadoop
文件:TestDFSPacket.java
@Test
public void testPacket() throws Exception {
Random r = new Random(12345L);
byte[] data = new byte[chunkSize];
r.nextBytes(data);
byte[] checksum = new byte[checksumSize];
r.nextBytes(checksum);
DataOutputBuffer os = new DataOutputBuffer(data.length * 2);
byte[] packetBuf = new byte[data.length * 2];
DFSPacket p = new DFSPacket(packetBuf, maxChunksPerPacket,
0, 0, checksumSize, false);
p.setSyncBlock(true);
p.writeData(data, 0, data.length);
p.writeChecksum(checksum, 0, checksum.length);
p.writeTo(os);
//we have set syncBlock to true, so the header has the maximum length
int headerLen = PacketHeader.PKT_MAX_HEADER_LEN;
byte[] readBuf = os.getData();
assertArrayRegionsEqual(readBuf, headerLen, checksum, 0, checksum.length);
assertArrayRegionsEqual(readBuf, headerLen + checksum.length, data, 0, data.length);
}
项目:BaseClient
文件:StructureNetherBridgePieces.java
public Start(Random p_i2059_1_, int p_i2059_2_, int p_i2059_3_)
{
super(p_i2059_1_, p_i2059_2_, p_i2059_3_);
this.primaryWeights = Lists.<StructureNetherBridgePieces.PieceWeight>newArrayList();
for (StructureNetherBridgePieces.PieceWeight structurenetherbridgepieces$pieceweight : StructureNetherBridgePieces.primaryComponents)
{
structurenetherbridgepieces$pieceweight.field_78827_c = 0;
this.primaryWeights.add(structurenetherbridgepieces$pieceweight);
}
this.secondaryWeights = Lists.<StructureNetherBridgePieces.PieceWeight>newArrayList();
for (StructureNetherBridgePieces.PieceWeight structurenetherbridgepieces$pieceweight1 : StructureNetherBridgePieces.secondaryComponents)
{
structurenetherbridgepieces$pieceweight1.field_78827_c = 0;
this.secondaryWeights.add(structurenetherbridgepieces$pieceweight1);
}
}
项目:Technical
文件:TechnicalWorldGenerator.java
private void generateSurface(World world, Random random, int startX, int startZ) {
/*
* if(startingX == 0 && startingZ == 0) { startingX = startX; startingZ = startZ; }
*
* if((startX > (startingX + 512)) || (startX < (startingX - 512))) { xWasBad = true; return; } else if(xWasBad) { if(!((startX > (startingX + 512)) || (startX < (startingX - 512)))) { FMLLog.log(Level.INFO,
* "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); startingX = startX; xWasBad = false; } }
*
* if((startZ > (startingZ + 512)) || (startZ < (startingZ - 512))) { zWasBad = true; return; } else if(zWasBad) { if(!((startZ > (startingZ + 512)) || (startZ < (startingZ - 512)))) { FMLLog.log(Level.INFO,
* "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"); startingZ = startZ; zWasBad = false; } }
*
* /* startingX = 0; startingZ = 0;
*/
for(int x = startX; x < startX + 16; x++) {
for(int z = startZ; z < startZ + 16; z++) {
removeStone(world, random, x, z);
}
}
addOresSurface(world, random, startX, startZ);
}
项目:BaseClient
文件:WorldGenDeadBush.java
public boolean generate(World worldIn, Random rand, BlockPos position)
{
Block block;
while (((block = worldIn.getBlockState(position).getBlock()).getMaterial() == Material.air || block.getMaterial() == Material.leaves) && position.getY() > 0)
{
position = position.down();
}
for (int i = 0; i < 4; ++i)
{
BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));
if (worldIn.isAirBlock(blockpos) && Blocks.deadbush.canBlockStay(worldIn, blockpos, Blocks.deadbush.getDefaultState()))
{
worldIn.setBlockState(blockpos, Blocks.deadbush.getDefaultState(), 2);
}
}
return true;
}
项目:openjdk-jdk10
文件:SubExactIRepeatTest.java
public static void runTest(Verify.BinaryMethod method) {
Random rnd = Utils.getRandomInstance();
for (int i = 0; i < 50000; ++i) {
int x = Integer.MIN_VALUE + 10;
int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);
int c = rnd.nextInt() / 2;
int d = rnd.nextInt() / 2;
int a = catchingExact(x, y, method);
if (a != 36) {
throw new RuntimeException("a != 36 : " + a);
}
int b = nonExact(c, d, method);
int n = exact(c, d, method);
if (n != b) {
throw new RuntimeException("n != b : " + n + " != " + b);
}
}
}
项目:greycat
文件:OffHeapLMatrix.java
@Override
public LMatrix fillWithRandom(long min, long max, long seed) {
container.lock();
try {
final long addr = container.addrByIndex(index);
if (addr != OffHeapConstants.NULL_PTR) {
final long nbRows = POffHeapLongArray.get(addr, INDEX_ROWS);
final long nbColumns = POffHeapLongArray.get(addr, INDEX_COLUMNS);
final Random rand = new Random();
rand.setSeed(seed);
for (int i = 0; i < nbColumns * nbRows; i++) {
POffHeapLongArray.set(addr, INDEX_OFFSET + i, rand.nextLong() * (max - min) + min);
}
container.declareDirty();
}
} finally {
container.unlock();
}
return this;
}
项目:btrace-demo
文件:RemoteClass.java
public static void main(String[] args) throws Exception {
while (true) {
Random random = new Random();
execute(random.nextInt(4000));
}
}
项目:openjdk-jdk10
文件:BigInteger.java
/**
* Returns {@code true} if this BigInteger is probably prime,
* {@code false} if it's definitely composite.
*
* This method assumes bitLength > 2.
*
* @param certainty a measure of the uncertainty that the caller is
* willing to tolerate: if the call returns {@code true}
* the probability that this BigInteger is prime exceeds
* {@code (1 - 1/2<sup>certainty</sup>)}. The execution time of
* this method is proportional to the value of this parameter.
* @return {@code true} if this BigInteger is probably prime,
* {@code false} if it's definitely composite.
*/
boolean primeToCertainty(int certainty, Random random) {
int rounds = 0;
int n = (Math.min(certainty, Integer.MAX_VALUE-1)+1)/2;
// The relationship between the certainty and the number of rounds
// we perform is given in the draft standard ANSI X9.80, "PRIME
// NUMBER GENERATION, PRIMALITY TESTING, AND PRIMALITY CERTIFICATES".
int sizeInBits = this.bitLength();
if (sizeInBits < 100) {
rounds = 50;
rounds = n < rounds ? n : rounds;
return passesMillerRabin(rounds, random);
}
if (sizeInBits < 256) {
rounds = 27;
} else if (sizeInBits < 512) {
rounds = 15;
} else if (sizeInBits < 768) {
rounds = 8;
} else if (sizeInBits < 1024) {
rounds = 4;
} else {
rounds = 2;
}
rounds = n < rounds ? n : rounds;
return passesMillerRabin(rounds, random) && passesLucasLehmer();
}
项目:DecompiledMinecraft
文件:StructureStrongholdPieces.java
public static StructureStrongholdPieces.Library func_175864_a(List<StructureComponent> p_175864_0_, Random p_175864_1_, int p_175864_2_, int p_175864_3_, int p_175864_4_, EnumFacing p_175864_5_, int p_175864_6_)
{
StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(p_175864_2_, p_175864_3_, p_175864_4_, -4, -1, 0, 14, 11, 15, p_175864_5_);
if (!canStrongholdGoDeeper(structureboundingbox) || StructureComponent.findIntersecting(p_175864_0_, structureboundingbox) != null)
{
structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(p_175864_2_, p_175864_3_, p_175864_4_, -4, -1, 0, 14, 6, 15, p_175864_5_);
if (!canStrongholdGoDeeper(structureboundingbox) || StructureComponent.findIntersecting(p_175864_0_, structureboundingbox) != null)
{
return null;
}
}
return new StructureStrongholdPieces.Library(p_175864_6_, p_175864_1_, structureboundingbox, p_175864_5_);
}
项目:MTweaks-KernelAdiutorMOD
文件:Values.java
public static int getUniqueId(List<Controls.ControlItem> items) {
Random random = new Random();
int r = random.nextInt(10000) + 1;
for (Controls.ControlItem item : items) {
if (item.getUniqueId() == r) {
return getUniqueId(items);
}
}
return r;
}
项目:Proyecto-DASI
文件:ClassroomDecoratorImplementation.java
private void drawPuzzle(World world, Random rand, Palette palette)
{
int doorLocation = this.front + rand.nextInt(this.back - this.front - 4) + 2;
for(int z=this.front; z<this.back; z++){
for(int y=this.bottom; y<this.top; y++){
setBlockState(world, new BlockPos(this.x,y,z), palette.wall);
}
if((z - this.front - 1) % 2 == 0 && z < this.back - 1){
setBlockState(world, new BlockPos(this.x - 1, this.bottom + ROOM_HEIGHT - 1, z), palette.light, null, Facing.WEST, null);
setBlockState(world, new BlockPos(this.x + 1, this.bottom + ROOM_HEIGHT - 1, z), palette.light, null, Facing.EAST, null);
}
}
Facing facing = this.getIn() == this.west ? Facing.WEST : Facing.EAST;
setBlockState(world, new BlockPos(this.x, this.bottom, doorLocation), palette.puzzleDoorLower, null, facing, null);
setBlockState(world, new BlockPos(this.x, this.bottom + 1, doorLocation), palette.puzzleDoorUpper, null, facing, null);
if(this.hint){
setBlockState(world, new BlockPos(this.x, this.bottom - 1, doorLocation), palette.hint);
setBlockState(world, new BlockPos(this.x, this.bottom - 1, doorLocation), palette.hint);
}
Room room = getIn();
int triggerZ;
if(rand.nextDouble() < 0.5){
triggerZ = doorLocation - 1;
}else{
triggerZ = doorLocation + 1;
}
if(room == this.west){
setBlockState(world, new BlockPos(this.x - 1, this.bottom + 1, triggerZ), palette.trigger, null, Facing.WEST, null);
}else{
setBlockState(world, new BlockPos(this.x + 1, this.bottom + 1, triggerZ), palette.trigger, null, Facing.EAST, null);
}
}
项目:CoreX
文件:BlockNetherWart.java
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().getId() != SOUL_SAND) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
} else if (type == Level.BLOCK_UPDATE_RANDOM) {
if (new Random().nextInt(10) == 1) {
if (this.meta < 0x03) {
BlockNetherWart block = (BlockNetherWart) this.clone();
++block.meta;
BlockGrowEvent ev = new BlockGrowEvent(this, block);
Server.getInstance().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
this.getLevel().setBlock(this, ev.getNewState(), true, true);
} else {
return Level.BLOCK_UPDATE_RANDOM;
}
}
} else {
return Level.BLOCK_UPDATE_RANDOM;
}
}
return 0;
}
项目:java_mooc_fi
文件:MainTest.java
@Test
public void testSums() {
int[] taulukoidenPituudet = {0, 1, 2, 3, 4, 5, 10, 20, 100};
Random random = new Random();
for (int i = 0; i < taulukoidenPituudet.length; i++) {
int pituus = taulukoidenPituudet[i];
int[] taulukko = new int[pituus];
for (int j = 0; j < taulukko.length; j++) {
taulukko[j] = random.nextInt(150);
}
tarkistaTaulukko(taulukko);
}
}
项目:JSiter
文件:UserService.java
public Map<String,Object> register(String username, String password){
Map<String,Object> map = new HashMap<>();
Random random = new Random();
// if (StringUtils.isBlank(username)){
// map.put("msg","用户名不能为空");
// return map;
// }
//
// if (StringUtils.isBlank(password)){
// map.put("msg","密码不能为空");
// return map;
// }
User u = userDao.selectByUserName(username);
if (u!=null){
// map.put("msg","用户名已经被占用");
// return map;
}
User user = new User();
user.setUsername(username);
user.setId(UUID.randomUUID().toString().substring(0,6));
// String ticket = addLoginTicket(user.getId());
// map.put("ticket",ticket);
map.put("user",user);
return map;
}
项目:ditb
文件:GoodBadUglyDB.java
private void delay() {
final Random random = Utils.random();
double p = random.nextDouble();
int mod;
if (p < 0.9) {
mod = 0;
} else if (p < 0.99) {
mod = 1;
} else if (p < 0.9999) {
mod = 2;
} else {
mod = 3;
}
// this will make mod 3 pauses global
Lock lock = mod == 3 ? DB_ACCESS.writeLock() : DB_ACCESS.readLock();
if (mod == 3) {
System.out.println("OUCH");
}
lock.lock();
try {
final long baseDelayNs = MICROSECONDS.toNanos(delays[mod]);
final int delayRangeNs = (int) (MICROSECONDS.toNanos(delays[mod + 1]) - baseDelayNs);
final long delayNs = baseDelayNs + random.nextInt(delayRangeNs);
final long deadline = System.nanoTime() + delayNs;
do {
LockSupport.parkNanos(deadline - System.nanoTime());
} while (System.nanoTime() < deadline && !Thread.interrupted());
} finally {
lock.unlock();
}
}
项目:NanoIconPack
文件:SimplePageTransformer.java
public SimplePageTransformer(int animType) {
if (animType == ANIM_RANDOM) {
int[] animTypes = {ANIM_DEFAULT, ANIM_ZOOM_OUT, ANIM_DEPTH};
this.animType = animTypes[(new Random()).nextInt(animTypes.length)];
} else {
this.animType = animType;
}
}
项目:CustomWorldGen
文件:StructureStrongholdPieces.java
public StairsStraight(int p_i45572_1_, Random p_i45572_2_, StructureBoundingBox p_i45572_3_, EnumFacing p_i45572_4_)
{
super(p_i45572_1_);
this.setCoordBaseMode(p_i45572_4_);
this.entryDoor = this.getRandomDoor(p_i45572_2_);
this.boundingBox = p_i45572_3_;
}
项目:DecompiledMinecraft
文件:StructureVillagePieces.java
public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
{
StructureVillagePieces.func_176069_e((StructureVillagePieces.Start)componentIn, listIn, rand, this.boundingBox.minX - 1, this.boundingBox.maxY - 4, this.boundingBox.minZ + 1, EnumFacing.WEST, this.getComponentType());
StructureVillagePieces.func_176069_e((StructureVillagePieces.Start)componentIn, listIn, rand, this.boundingBox.maxX + 1, this.boundingBox.maxY - 4, this.boundingBox.minZ + 1, EnumFacing.EAST, this.getComponentType());
StructureVillagePieces.func_176069_e((StructureVillagePieces.Start)componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.maxY - 4, this.boundingBox.minZ - 1, EnumFacing.NORTH, this.getComponentType());
StructureVillagePieces.func_176069_e((StructureVillagePieces.Start)componentIn, listIn, rand, this.boundingBox.minX + 1, this.boundingBox.maxY - 4, this.boundingBox.maxZ + 1, EnumFacing.SOUTH, this.getComponentType());
}
项目:openjdk-jdk10
文件:JVMStartupRunner.java
/**
* 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;
}
项目:BaseClient
文件:StructureStrongholdPieces.java
public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
{
if (this.coordBaseMode != EnumFacing.NORTH && this.coordBaseMode != EnumFacing.EAST)
{
this.getNextComponentX((StructureStrongholdPieces.Stairs2)componentIn, listIn, rand, 1, 1);
}
else
{
this.getNextComponentZ((StructureStrongholdPieces.Stairs2)componentIn, listIn, rand, 1, 1);
}
}
项目:alfresco-repository
文件:PropValGenerator.java
@Override
protected Date createValue()
{
Random rand = new Random();
Date date = new Date(rand.nextLong());
// Dates are stored to day precision, make sure we return the
// same value that will be stored, for comparison in assert statements etc.
Date truncDate = PropertyDateValueEntity.truncateDate(date);
return truncDate;
}
项目:s-store
文件:TestSqlAggregateSuite.java
public void testMultipleAverages() throws IOException, ProcCallException {
String[] tables = {"P1", "R1"};
Random rand = this.getRandom();
for (String table : tables) {
Client client = getClient();
List<Long> val_nums = new ArrayList<Long>();
List<Double> val_ratios = new ArrayList<Double>();
for (int i = 0; i < ROWS; ++i) {
BigDecimal cash = new BigDecimal(10.0);
long num = i / 2;
double ratio = rand.nextDouble();
client.callProcedure("Insert", table, i, "desc", cash, num, ratio);
val_nums.add(num);
val_ratios.add(ratio);
} // FOR
double expected_results[] = {
MathUtil.arithmeticMean(val_nums),
MathUtil.arithmeticMean(val_ratios),
};
String query = String.format("SELECT AVG(NUM), AVG(RATIO) FROM %s", table);
VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
assertEquals(1, results.length);
assertEquals(1, results[0].getRowCount());
assertTrue(results[0].advanceRow());
for (int i = 0; i < expected_results.length; ++i) {
double val = ((Number)results[0].get(i, results[0].getColumnType(i))).doubleValue();
assertEquals(table+"."+i, expected_results[i], val, 0.00001);
} // FOR
} // FOR
}
项目:imagingbook-common
文件:KMeansClusteringQuantizer.java
/**
* We randomly pick k distinct colors from the original image
* pixels.
* @param pixels
* @param k
* @return
*/
private int[] getColorSamples(int[] pixels, int k) {
switch (params.samplMethod) {
case Random:
return getRandomColors(pixels, k);
case Most_Frequent:
return getMostFrequentColors(pixels, k);
default:
return null;
}
}
项目:candlelight
文件:WeightedSet.java
public E getRandomWeightedValue(Random rand)
{
int target = rand.nextInt(this.getTotalWeight());
int index = 0;
for(int i = 0; i < this.mapping.size() - 1; ++i)
{
index += this.mapping.valueAt(i);
if (index >= target)
{
return this.mapping.keyAt(i);
}
}
return this.mapping.keyAt(this.mapping.size() - 1);
}
项目:mirrorgate-jenkins-builds-collector
文件:MirrorGateListenerHelperTest.java
@Test
public void sendBuildFromItemResponseError() {
when(service.publishBuildData(any())).thenReturn(responseError);
when(service.sendBuildDataToExtraEndpoints(any(), any())).thenReturn(responseError);
Job[] jobs = new Job[new Random().nextInt(10)];
Arrays.fill(jobs, createMockingJob());
helper.sendBuildFromItem(createMockingItem(jobs));
verify(service, times(jobs.length)).publishBuildData(any());
}
项目:CustomWorldGen
文件:StructureNetherBridgePieces.java
public static StructureNetherBridgePieces.Corridor5 createPiece(List<StructureComponent> p_175877_0_, Random p_175877_1_, int p_175877_2_, int p_175877_3_, int p_175877_4_, EnumFacing p_175877_5_, int p_175877_6_)
{
StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(p_175877_2_, p_175877_3_, p_175877_4_, -1, 0, 0, 5, 7, 5, p_175877_5_);
/**
* Checks if the bounding box's minY is > 10
*/
return isAboveGround(structureboundingbox) && StructureComponent.findIntersecting(p_175877_0_, structureboundingbox) == null ? new StructureNetherBridgePieces.Corridor5(p_175877_6_, p_175877_1_, structureboundingbox, p_175877_5_) : null;
}