1 package jcryptoboard
.actions
.rng
;
3 import java
.security
.NoSuchAlgorithmException
;
4 import java
.security
.SecureRandom
;
5 import jcryptoboard
.api
.model
.AbstractAction
;
6 import jcryptoboard
.api
.model
.ActionResult
;
7 import org
.apache
.commons
.lang
.mutable
.MutableInt
;
10 * Created with IntelliJ IDEA.
14 * To change this template use File | Settings | File Templates.
16 public class Random
extends AbstractAction
{
18 private java
.util
.Random rnd
= new java
.util
.Random();
20 public void setSecure(String algo
) {
22 rnd
= SecureRandom
.getInstance(algo
);
23 } catch (NoSuchAlgorithmException e
) {
24 throw new IllegalArgumentException("Invalid SecureRandom algorithm: " + algo
);
29 private void recompute()
31 integer
.setValue(rnd
.nextInt());
36 * Updates buffers with new random values.
39 public ActionResult
execute() throws Exception
{
41 return nextAction
.execute();
44 private byte[] array
= new byte[8];
45 private MutableInt integer
= new MutableInt(0);
52 /** Returns random integer */
53 public void setInteger(MutableInt integer
) {
54 this.integer
= integer
;
57 /** Returns random integer */
58 public MutableInt
getInteger() {
63 * Instructs action to provide array of random bytes of given length.
66 public void setProvideArray(int length
)
68 array
= new byte[length
];
71 public void setArray(byte[] array
) {
73 throw new NullPointerException("Array buffer for Random must not be null.");
79 * Returns random bytes in array.
80 * By default 8 bytes are provided. This can by changed by calling setArray or setProvideArray.
82 public byte[] getArray() {
86 public String
getName() {