gpt4 book ai didi

java - long seed = 11L*13*17*19*23+1是什么意思;在上面的代码中?

转载 作者:行者123 更新时间:2023-11-30 06:11:04 24 4
gpt4 key购买 nike

一个演示如何使用 GridSim 包的简单程序。 * 此示例显示网格用户如何提交其 Gridlet 或 * 一个网格资源实体的任务。

private GridletList createGridlet(int userID)
{
// Creates a container to store Gridlets
GridletList list = new GridletList();

// We create three Gridlets or jobs/tasks manually without the help
// of GridSimRandom
int id = 0;
double length = 3500.0;
long file_size = 300;
long output_size = 300;
Gridlet gridlet1 = new Gridlet(id, length, file_size, output_size);
id++;
Gridlet gridlet2 = new Gridlet(id, 5000, 500, 500);
id++;
Gridlet gridlet3 = new Gridlet(id, 9000, 900, 900);

// setting the owner of these Gridlets
gridlet1.setUserID(userID);
gridlet2.setUserID(userID);
gridlet3.setUserID(userID);

// Store the Gridlets into a list
list.add(gridlet1);
list.add(gridlet2);
list.add(gridlet3);

// We create 5 Gridlets with the help of GridSimRandom and
// GriSimStandardPE class
long seed = 11L*13*17*19*23+1;
Random random = new Random(seed);

// sets the PE MIPS Rating
GridSimStandardPE.setRating(100);

// creates 5 Gridlets
int count = 5;
for (int i = 1; i < count+1; i++)
{
// the Gridlet length determines from random values and the
// current MIPS Rating for a PE
length = GridSimStandardPE.toMIs(random.nextDouble()*50);

// determines the Gridlet file size that varies within the range
// 100 + (10% to 40%)
file_size = (long) GridSimRandom.real(100, 0.10, 0.40,
random.nextDouble());

// determines the Gridlet output size that varies within the range
// 250 + (10% to 50%)
output_size = (long) GridSimRandom.real(250, 0.10, 0.50,
random.nextDouble());

// creates a new Gridlet object
Gridlet gridlet = new Gridlet(id + i, length, file_size,
output_size);

gridlet.setUserID(userID);

// add the Gridlet into a list
list.add(gridlet);
}

return list;
}

最佳答案

如果将种子添加到 Random,每次运行代码时都会得到相同的结果。如果没有提供种子,java 会自己选择一个种子(基于当前时间)。这是伪随机数生成器的一个特点。参见 Java Random Numbers Using a Seed以获得更详尽的解释。

关于java - long seed = 11L*13*17*19*23+1是什么意思;在上面的代码中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34740648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com