Skip to content

Instantly share code, notes, and snippets.

@visparashar
Created November 4, 2017 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visparashar/b027476e14f98608f13ff19890e34956 to your computer and use it in GitHub Desktop.
Save visparashar/b027476e14f98608f13ff19890e34956 to your computer and use it in GitHub Desktop.
public class RandomGenerator {
public static void main(String[] args) {
// for getting 50% probability of 0 and 1
System.out.println("For 50% of 0 and 1 probability "+random50());
// for getting 75% probability of 1
System.out.println("For getting 75% probability of 1 as output :"+random75());
}
public static int random50() {
if(Math.random() <0.5)
return 1;
return 0;
}
public static int random75() {
return random50() | random50();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment