CP2004 – Assignment, 2008, BJUT
Due date: 9am 28th of November
Part 1: 10%
In recent years, an alternative to the traditional uniform pseudo-random number generators (e.g. the rand() function in C/C++ or the Random class in Java) are becoming popular. These alternative generators are called Lagged Fibonacci pseudo-random number generators (or LFGs for short). LFGs are based on the Fibonacci sequence, which is generated by the formula:
X(n) = X(n-1) + X(n-2) where n > 1 and X(1) = X(0) = 1
the sequence of numbers produced is:
1, 1, 2, 3, 5, 8, 13, ...
An LFG sequence is generated by the formula: 一LFG序列被公式产生:
X(n) = (X(n-L) + X(n-k)) % m where L > k > 0, and m > 0
where X(0) … X(L-1) are pre-defined预先定义 (i.e. they are seed values).
For more information see: http://www.csep1.phy.ornl.gov/rn/node20.html
Task
Write a java program capable of generating various LFG sequences. 写一个能产生各种各样LFG序列的java程序. The program must use command-line parameters to allow initialisation for the values of L (the first lag number), k (the second lag number), m (the mod number), and n (the total number of values to generate). 程序必须使用参数命令行使得这几个值初始化。For example, here is one possible output of your program: 例如,以下是你程序的输出
$ java AssignmentOne
Usage: java AssignmentOne L k m seeds n $ java AssignmentOne 4 3 10 1 2 3 4 10
[3,5,7,7,8,2,4,5,0,6]
The first example execution shows that on invalid command-line parameters a usage message appears. In the second example, a sequence of pseudo random numbers are displayed where the LFG values are: L = 4, k = 3, m = 10, X(0) = 1, X(1) = 2, X(2) = 3, X(3) = 4, and n = 10. Requirements要求哦
Students are required to produce their own solutions to this task by constructing the following source code files:
• File: AssignmentOne.java
o The main java program for this task, it is used to extract the command-line parameters and activate a LFG object.
• File: LaggedFib.java
o The LFG class, contains an interface for specifying the LFG values and for generating the pseudo random numbers.
o A Vector object must be used to store the LFG seed values within a LFG object.
Due date: 9am 28th of November
Part 1: 10%
In recent years, an alternative to the traditional uniform pseudo-random number generators (e.g. the rand() function in C/C++ or the Random class in Java) are becoming popular. These alternative generators are called Lagged Fibonacci pseudo-random number generators (or LFGs for short). LFGs are based on the Fibonacci sequence, which is generated by the formula:
X(n) = X(n-1) + X(n-2) where n > 1 and X(1) = X(0) = 1
the sequence of numbers produced is:
1, 1, 2, 3, 5, 8, 13, ...
An LFG sequence is generated by the formula: 一LFG序列被公式产生:
X(n) = (X(n-L) + X(n-k)) % m where L > k > 0, and m > 0
where X(0) … X(L-1) are pre-defined预先定义 (i.e. they are seed values).
For more information see: http://www.csep1.phy.ornl.gov/rn/node20.html
Task
Write a java program capable of generating various LFG sequences. 写一个能产生各种各样LFG序列的java程序. The program must use command-line parameters to allow initialisation for the values of L (the first lag number), k (the second lag number), m (the mod number), and n (the total number of values to generate). 程序必须使用参数命令行使得这几个值初始化。For example, here is one possible output of your program: 例如,以下是你程序的输出
$ java AssignmentOne
Usage: java AssignmentOne L k m seeds n $ java AssignmentOne 4 3 10 1 2 3 4 10
[3,5,7,7,8,2,4,5,0,6]
The first example execution shows that on invalid command-line parameters a usage message appears. In the second example, a sequence of pseudo random numbers are displayed where the LFG values are: L = 4, k = 3, m = 10, X(0) = 1, X(1) = 2, X(2) = 3, X(3) = 4, and n = 10. Requirements要求哦
Students are required to produce their own solutions to this task by constructing the following source code files:
• File: AssignmentOne.java
o The main java program for this task, it is used to extract the command-line parameters and activate a LFG object.
• File: LaggedFib.java
o The LFG class, contains an interface for specifying the LFG values and for generating the pseudo random numbers.
o A Vector object must be used to store the LFG seed values within a LFG object.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货