Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


creating less predictible random? -Java
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Oct 04, 2009 11:19 am    Post subject: creating less predictible random? -Java Reply with quote

Yea i took Comp sci and have been forced to switch to java for the time being.

Code:
       SecureRandom generator = new SecureRandom();
        generator.setSeed(generator.nextInt(2147483647));
        generator.setSeed(generator.nextInt(2147483647));
        generator.setSeed(generator.nextInt(2147483647));
        generator.setSeed(generator.nextInt(2147483647));


Basically, would creating a random number generator like that be more secure than just declaring and not setting seeds? In my eyes, it would become harder and harder to find the correct seed with more random generations.

Here's my logic:

Create the generator with an initial random seed based on system time
Take that random generator and generate a number with it, pass this for the seed.
Keep doing that until you are satisfied (if this is more secure i would probably do 100 iterations).

_________________
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Oct 04, 2009 12:14 pm    Post subject: Reply with quote

Seed using the current time.

Alternatively: http://www.random.org/clients/http/
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Oct 04, 2009 12:19 pm    Post subject: Reply with quote

the initial seed is using current time, which is predictable.

Also i'm just doing this for a small school example, no use in using an outside class.

I finished the program he wanted in 5 minutes, and he was like "Well try to make them more random (acting like he can predict them)."

_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sun Oct 04, 2009 12:38 pm    Post subject: Reply with quote

blankrider wrote:
the initial seed is using current time, which is predictable.
If you use the result as the seed, it's predictable too.. That's why they're called pseudo random numbers. The only way to get a more random number is eg. get some RF receiver, record some noise from there and use it. Also, you could record some mouse movement or sth.

blankrider wrote:
I finished the program he wanted in 5 minutes, and he was like "Well try to make them more random (acting like he can predict them)."
You could manipulate the distribution a bit. Eg. if your output is limited to certain range, you could do:
Code:
int result = (int)( ( (double)( rand() )/RAND_MAX )*( max ) )
or something instead of
Code:
int result = rand()%max;
Back to top
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Sun Oct 04, 2009 6:09 pm    Post subject: Reply with quote

you could try to take a random part of the random number too
e.g.
floor((random1 * (10 ^ random2)) % 10)
and repeat that to the number of digits you need to get something like this
Code:
var rand = 0, i = 0, digits = 10;
for(i=0;i<digits;i++){
 rand += (Math.floor((Math.random() * Math.pow(10, Math.random())) % 10)) * Math.pow(10,i);
}
rand;

and you could further overlap this to get something like
Code:
var rand = 0, i = 0, overlap = 3, digits = 10;
for(i=0;i<digits-overlap;i++){
 rand += (Math.floor((Math.random() * Math.pow(10, Math.random())) % Math.pow(10,overlap))) * Math.pow(10,i);
}
rand;


Last edited by shhac on Sun Oct 04, 2009 6:42 pm; edited 3 times in total
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Oct 04, 2009 6:30 pm    Post subject: Reply with quote

Jani wrote:
blankrider wrote:
the initial seed is using current time, which is predictable.
If you use the result as the seed, it's predictable too.. That's why they're called pseudo random numbers. The only way to get a more random number is eg. get some RF receiver, record some noise from there and use it. Also, you could record some mouse movement or sth.

blankrider wrote:
I finished the program he wanted in 5 minutes, and he was like "Well try to make them more random (acting like he can predict them)."
You could manipulate the distribution a bit. Eg. if your output is limited to certain range, you could do:
Code:
int result = (int)( ( (double)( rand() )/RAND_MAX )*( max ) )
or something instead of
Code:
int result = rand()%max;


I'm trying to understand why

Code:
y = (int)( ( (double)( generator.nextInt(100) )/100 )*( 100 ) );


will make it more distributed. Care to explain? It looks to me like your just dividing the rand by 100 then multiplying by 100. How does that affect the distribution

_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Oct 05, 2009 2:23 am    Post subject: Reply with quote

blankrider wrote:
It looks to me like your just dividing the rand by 100 then multiplying by 100. How does that affect the distribution
First of all, it seems that nextInt limits the upper bound already, so you can forget everything I've said :P Also, it's said that the result is already dirstributed uniformly between 0 and n. So it's better to read the docs before doing any posts. :P I'll explain how the things are in C anyway:

RAND_MAX is the maxium value your rand() will output, eg. 0x7FFF. Do you understand now why it's different?

Let's say you generate 8 bits of random stuff -> max is 255d. If the max you want is 250, to scale it, you need to divide by 255 and then multiply with the max, 250.

Then think a little about the the other method, it'll use the left over, so it isn't distributed equally. Let's say your max is 3 and the maxium number you're getting from rand() is 4:
Code:
0%3 == 0
1%3 == 1
2%3 == 2
3%3 == 0
4%3 == 1
See, you're getting twice as much ones and zeroes than twos.. Now do the same with scaling it and see the result.

Okay, and now back to the question. Noticed this while reading the reference:
Code:
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
is said to be completely random unless you call .setSeed(). So I think that could result in a better outcome..
Back to top
View user's profile Send private message
TheRealLinky
How do I cheat?
Reputation: 0

Joined: 18 Jun 2009
Posts: 7

PostPosted: Mon Oct 05, 2009 3:46 pm    Post subject: Reply with quote

why not just use your audio in jack as a seed and you pretty much get a nist grade prng.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Oct 05, 2009 3:48 pm    Post subject: Reply with quote

TheRealLinky wrote:
why not just use your audio in jack as a seed and you pretty much get a nist grade prng.


how would i go about that? I'm pretty new to java Razz

_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Oct 06, 2009 5:14 am    Post subject: Reply with quote

TheRealLinky wrote:
why not just use your audio in jack as a seed and you pretty much get a nist grade prng.
Just make sure no microphone is plugged in and that the jack is really working...
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Tue Oct 06, 2009 7:59 pm    Post subject: Reply with quote

how would i use that as a seed? I dont know how to get a handle to it in java.
_________________
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Tue Oct 06, 2009 9:51 pm    Post subject: Reply with quote

Code:
import javax.sound.sampled.*;
import java.io.*;

public class Test {
   public static void main(String args[])
   {
      Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
      AudioFormat audioFormat = new AudioFormat(
      AudioFormat.Encoding.PCM_SIGNED,
      44100.0F, 16, 2, 4, 44100.0F, false);

      Port.Info portInfo = new Port.Info(TargetDataLine.class,
      Port.Info.SPEAKER.getName(), false);
      DataLine.Info dataLineInfo = new
      DataLine.Info(portInfo.getLineClass(),
      audioFormat);
      Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);

      TargetDataLine targetDataLine = null;
      try {
         targetDataLine = (TargetDataLine)mixer.getLine(dataLineInfo);
         targetDataLine.open(audioFormat);
      } catch ( Exception e) { System.out.println("E: "+e); }
      int numBytesAvailable = targetDataLine.available();


      BufferedReader br = new BufferedReader(new
      InputStreamReader(System.in));
      String exitQ = null;

      targetDataLine.start();
      while(true) {
         byte tempBuffer[] = new byte[10000];

         targetDataLine.read(tempBuffer, 0, tempBuffer.length);
         System.out.println(tempBuffer.toString());
         System.out.println("# bytes available = "+numBytesAvailable);


         try {
            exitQ = br.readLine();
         } catch (IOException ioe) {
            System.out.println("IO error trying read exit code!");
            System.exit(1);
         }
         if (exitQ.charAt(0)=='e') { System.out.println("Goodbye");
            System.exit(1); } //type e to exit
      }
   }


Try something like that?

- From bottom of: http://www.techtalkz.com/java/104007-reading-sound-card-output.html
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Fri Oct 09, 2009 4:32 am    Post subject: Reply with quote

distribution wise, java's number generator is spot on (at least in my context). Using a test of 10000 * 100 numbers, there is about a 9.94 - 10.06% distribution (with 10 being perfect, and possible numbers from 1-10).

In the end i used SHA1PRNG algorithm in SecureRandom. Note this was for a simple java project in school and i was trying to somewhat stick to the classes in informed everyone to use (just plain Random)

_________________
Back to top
View user's profile Send private message
TheRealLinky
How do I cheat?
Reputation: 0

Joined: 18 Jun 2009
Posts: 7

PostPosted: Fri Oct 09, 2009 2:25 pm    Post subject: Reply with quote

If that was the case id have gone with the NIST grade seed to show off.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Fri Oct 09, 2009 9:38 pm    Post subject: Reply with quote

TheRealLinky wrote:
If that was the case id have gone with the NIST grade seed to show off.


Too much effort lol. I already showed up the teacher on the assignment by proving his way was not more random than mine. What a froob

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites