Page 1 of 1

Generate random number

Posted: Sun Jul 23, 2017 11:51 pm
by Christy16
I am trying to generate random number for a get challenge command, but every time I always got the same number, I need a 8 byte unique number generated every time.Here is my code. Can anyone help me out? Thanks a lot.

Code: Select all

         byte[] apduBuffer = apdu.getBuffer();
         RandomData random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
         byte[] randomArray = new byte[8];
          random.setSeed(randomArray,(short)0,(short)8);
         random.generateData(randomArray,(short)0, (short)8);
         Util.arrayCopy(randomArray,(short)0,apduBuffer,(short)0,(short)8);
         apdu.setOutgoingAndSend((short)0, (short)8);

Re: Generate random number

Posted: Mon Jul 24, 2017 11:12 pm
by Crawford
If you remove the setSeeed call, you will get a different result from the random number generator, since you are seeding the generator with the same value.