Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Is this code sufficient for my purposes?

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is this code sufficient for my purposes?

    I'm not a programmer. I've been playing poker and I want a tool to simulate some results to better understand variance.

    I played a 100 games with each game consisting of 3 players in a winner take all format (so with all else being equal there is a 33.3% chance of winning).

    Despite adhering strictly to GTO strategy I found myself under the average of 33.3% with a 28% win rate. In fact at one point I lost 11 games in a row. This is discouraging however I decided I should manage my expectations with context.

    I put together this code to simulate playing 100 games x 10, however I am told that this may not produce true random results and I was wondering if there is a better method or piece of code that would be more inline with reality. If it's not true random then this exercise is somewhat pointless.

    Since I'm not programmer and a stupid head you might have to spell it out for me. I actually downloaded eclipse today just for this.

    Thanks guys!

     
    import java.util.Random;
     
    public class Random1Class {
     
    	public static void main(String[] args) {
     
    		int win = 0;	
     
    		Random rand = new Random();
    		int randomNum;
     
     
    for(int v = 0; v < 10; v++) {		
     
    		for(int i = 0; i < 100; i++) {
     
    			randomNum = rand.nextInt((100 - 1) + 1) + 1;
     
    			if( randomNum <= 33.3) {		
    				win = win + 1;	
    				}	
    		}
     
    		System.out.println(win);
    		win = 0;
    }		
     
     
     
    	}
     
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Is this code sufficient for my purposes?

    Not sure what that simple code is supposed to test. What happens when you run it for 10000 times vs 100?

    Note: This program has nothing to do with java programming. It seems more about math.
    The results would be similar for any language the code was written in.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2022
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is this code sufficient for my purposes?

    Well it's about finding out what kind of range I can expect to see. For example results above 40 are exceptionally rare but apparently happen.

    Well I'm using a Java library function and since I'm not that versed in Java I would like to know whether it's sufficient. The program depends on Math and the Java implementation doesn't it. For example one concern I heard is that calling the random method in short succession doesn't give properly dispersed results. So that's not so much math as what Java does right?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Is this code sufficient for my purposes?

    properly dispersed
    The dispersal of numbers would be random, not uniform. 1,2,2,3,2,1,1,1 could be a random sequence of numbers.
    If the numbers are to be uniformly dispersed then the sample size needs to be much larger than 100.

    Also the code compares an int value against a double: 33.3 The int value will either be 33 or 34 and nothing in between.
    If you want values between 33.0 and 33.9 then you need to use a double variable and call a different method.

    BTW I am not a mathematician.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2022
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Is this code sufficient for my purposes?

    By dispersed I meant on on a implementation level... As is computers find it hard to simulate randomness and having this method repeatedly called close together creates an artificial bias (a tightening of the range as a result of seed bias). Does that make sense? I mean it's just what I have heard when I looked up this function. If you think it's doing it's job and there isn't a bias then I guess it's ok as is. And good catch with the float I'll fix that.

Similar Threads

  1. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  2. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  3. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  4. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 04:38 PM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM