made this program this morning while acquainting myself with java swing. not sure if there is a program already like it but w/e.
Basically if you're in a spot that you want to call or bet say 33% of the time or half etc... you type it in and see if it's that time or not. This way you're not guessing how often you're doing something.
You can also test the algorithm in case you're wondering if it's random enough.
Green background means to do whatever you wanted to do that % of time
Red background means don't do it.
You'll have to figure out how to use it and what spots, I don't have the answers for that.
you can download it here and just run the jar if you have java installed
http://www.mediafire.com/?we2gyyh30gm
if you don't have java
http://www.java.com/en/download/index.jsp
screenshot (yeah pretty basic
)
comments or suggestions welcome
Code:
package Randomizer;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.*;
import java.util.Random;
import javax.swing.JTextArea;
public class Randomizer extends JPanel implements ActionListener {
private JButton goButton = new JButton("Balance");
private JButton resetButton = new JButton("Reset");
private JButton testButton = new JButton("Test");
private JTextField balance = new JTextField(2);
private JTextArea ta = new JTextArea(3, 10);
public Randomizer() {
add(resetButton);
add(goButton);
add(balance);
add(testButton);
add(ta);
balance.setText("0");
goButton.addActionListener(this);
resetButton.addActionListener(this);
testButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
int entry = 0;
Object source = evt.getSource();
Color color = getBackground();
if (source == resetButton){
color = Color.white;
balance.setText("0");
ta.setText("");
}
else if (source == goButton){
entry = getter();
int random = rando();
if (random < entry){
color = Color.green;
ta.setText("Go Go Go!");
}else if (random >= entry){
color = Color.red;
ta.setText("No No No!");
}
}
else if (source==testButton)
tester();
setBackground(color);
repaint();
}
public int getter(){
int e = 0;
try {
e = Integer.parseInt(balance.getText());
}catch ( NullPointerException npe ) { e = 0;}
catch ( NumberFormatException nfe ) { e = 0; }
return e;
}
public void tester(){
ta.setText("");
int pos = 0; int neg = 0;
int testEntry = getter();
for (int i = 0;i<100000;i++){
int testRand = rando();
if (testRand < testEntry)
pos++;
else if (testRand >= testEntry)
neg++;
}
ta.append("Testing 100000 simulations\n");
ta.append("There were " + pos + " positives\n");
ta.append("There were " + neg + " negatives\n");
}
public static int rando(){
int hi = 99; int lo = 0;
Random rn = new Random();
int n = hi - lo + 1;
int i = rn.nextInt() % n;
if (i < 0)
i = -i;
return lo + i;
}
public static void main(String[] args) {
JFrame frame = new JFrame("Range Balancer by jwc529");
frame.setSize(275, 125);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new Randomizer());
frame.show();
}
}