games.strategy.engine.random
Class CryptoRandomSource

java.lang.Object
  extended by games.strategy.engine.random.CryptoRandomSource
All Implemented Interfaces:
IRandomSource

public class CryptoRandomSource
extends java.lang.Object
implements IRandomSource

A random source that generates numbers using a secure algorithm shared between two players. Code originally contributed by Ben Giddings.


Constructor Summary
CryptoRandomSource(PlayerID remotePlayer, IGame game)
           
 
Method Summary
static int[] bytesToInts(byte[] bytes)
           
 int[] getRandom(int max, int count, java.lang.String annotation)
          Delegates should not use random data that comes from any other source.
 int getRandom(int max, java.lang.String annotation)
          All delegates should use random data that comes from both players so that neither player cheats.
static byte[] intsToBytes(int[] ints)
          converts an int[] to a bytep[
static int[] xor(int[] val1, int[] val2, int max)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoRandomSource

public CryptoRandomSource(PlayerID remotePlayer,
                          IGame game)
Method Detail

intsToBytes

public static byte[] intsToBytes(int[] ints)
converts an int[] to a bytep[


bytesToInts

public static int[] bytesToInts(byte[] bytes)

xor

public static int[] xor(int[] val1,
                        int[] val2,
                        int max)

getRandom

public int getRandom(int max,
                     java.lang.String annotation)
All delegates should use random data that comes from both players so that neither player cheats.

Specified by:
getRandom in interface IRandomSource

getRandom

public int[] getRandom(int max,
                       int count,
                       java.lang.String annotation)
Delegates should not use random data that comes from any other source.

Specified by:
getRandom in interface IRandomSource