VB icon

Pandora Box

Email
Submitted on: 11/9/2016 7:09:17 AM
By: Zehel  
Level: Advanced
User Rating: Unrated
Compatibility: Java (JDK 1.4), Java (JDK 1.5)
Views: 2010
author picture
 
     Creates a random all binary java method.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Pandora Box
// Description:Creates a random all binary java method.
// By: Zehel
//**************************************

//••••----------••••
private String pndrsBx() {
String retStr="";String retRayNm="";
String alpBt="abcdefghijklmnopqrstuvwxyz";Random rnd=new Random();
int boolRptVars=rnd.nextInt(15);
if(boolRptVars==0||boolRptVars==1||boolRptVars==2||boolRptVars==3){
boolRptVars=4;}try{String[] boolNms=getBoolVars(boolRptVars);
int prmsCnt=rnd.nextInt(24);
if(prmsCnt==0||prmsCnt==1||prmsCnt==2||prmsCnt==3){prmsCnt=4;}
retStr="public static Boolean[] ";
retStr=retStr+"__"+String.valueOf(alpBt.charAt(rnd.nextInt(26))).toUpperCase();
retStr=retStr+String.valueOf(alpBt.charAt(rnd.nextInt(26))).toUpperCase();
retStr=retStr+String.valueOf(alpBt.charAt(rnd.nextInt(26))).toUpperCase();
retStr=retStr+"_"+String.valueOf(rnd.nextInt(9))+String.valueOf(rnd.nextInt(9));
retStr=retStr+String.valueOf(rnd.nextInt(9))+String.valueOf(rnd.nextInt(9))+"(";
for(int h=0;h<prmsCnt;h++){if(h+1!=prmsCnt){
retStr=retStr+"Boolean "+String.valueOf(alpBt.charAt(h))+",";}else{
retStr=retStr+"Boolean "+String.valueOf(alpBt.charAt(h))+"){"+"\n";}}
for(int i=0;i<boolNms.length;i++){retStr=retStr+"Boolean "+boolNms[i]+"=";
if(rnd.nextInt(66)>33){retStr=retStr+"true;"+"\n";}else{
retStr=retStr+"false;"+"\n";}}retRayNm=String.valueOf(alpBt.charAt(rnd.nextInt(26)))+"_";
retRayNm=retRayNm+String.valueOf(rnd.nextInt(9))+String.valueOf(rnd.nextInt(9));
retStr=retStr+"Boolean[] "+retRayNm+"=new Boolean["+String.valueOf(prmsCnt)+"];"+"\n";
for(int j=0;j<prmsCnt;j++){
retStr=retStr+retRayNm+"["+String.valueOf(j)+"]="+String.valueOf(alpBt.charAt(j))+";"+"\n";}
retStr=retStr+getBoolIfComp(prmsCnt,boolNms)+"\n";retStr=retStr+"}"+"\n"+"return ";
retStr=retStr+retRayNm+";"+"}";}catch(Exception e){}return retStr;}
//••••----------••••
private String getBoolIfComp(int ttlBoolRpt,String[] strBoolNms){
String retStr="";Random rnd=new Random();
int rpt=0;int rptB=0;int rptExp=0;int expLen=0;
rpt=rnd.nextInt(24);if(rpt==0||rpt==1||rpt==2){
rpt=3;}for(int i=0;i<rpt;i++){
if(rnd.nextInt(66)>33){expLen=rnd.nextInt(8);
if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";
if(rnd.nextInt(66)>33){rptExp=rnd.nextInt(3);
if(rptExp==0||rptExp==1||rptExp==2){rptExp=3;}for(int j=0;j<rptExp;j++){
expLen=rnd.nextInt(8);if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";}}
retStr=retStr+"\n";}else{if(rnd.nextInt(66)>33){
rptExp=rnd.nextInt(3);if(rptExp==0||rptExp==1||rptExp==2){rptExp=3;}
for(int k=0;k<rptExp;k++){expLen=rnd.nextInt(8);
if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";}}rptB=rnd.nextInt(6);
if(rptB==0||rptB==1||rptB==2){rptB=3;}for(int l=0;l<rptB;l++){
retStr=retStr+getBoolIfCond(ttlBoolRpt,strBoolNms)+"\n";if(rnd.nextInt(66)>33){
expLen=rnd.nextInt(8);if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";}
if(rnd.nextInt(66)>33){expLen=rnd.nextInt(8);
if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";}}
retStr=retStr+"}"+"\n"+"else{"+"\n";expLen=rnd.nextInt(8);
if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";
if(rnd.nextInt(66)>33){expLen=rnd.nextInt(8);
if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";}if(rnd.nextInt(66)>33){
expLen=rnd.nextInt(8);
if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";}
if(rnd.nextInt(66)>33){expLen=rnd.nextInt(8);
if(expLen==0||expLen==1||expLen==2){expLen=3;}
retStr=retStr+getBoolExp(ttlBoolRpt,strBoolNms,expLen)+"\n";}
retStr=retStr+"}"+"\n";}}return retStr;}
//••••----------••••
private String getBoolIfCond(int ttlBoolRpt,String[] strBoolNms){
String retStr="";Random rnd=new Random();int w=0;
int cndLen=rnd.nextInt(15);Boolean hltCnd=false;if(rnd.nextInt(66)>33){
retStr="if(!";hltCnd=true;}else{retStr="if(";}
retStr=retStr+getRandBool(ttlBoolRpt,strBoolNms);
for(int i=0;i<cndLen;i++){w=rnd.nextInt(7);if(w==0){
retStr=retStr+"|"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==1){
retStr=retStr+"&"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==2){
retStr=retStr+"^"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==3){
retStr=retStr+"||"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==4){
retStr=retStr+"&&"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==5){
if(!hltCnd){hltCnd=true;
retStr=retStr+"=="+getRandBool(ttlBoolRpt,strBoolNms);}}
else if(w==6){if(!hltCnd){
hltCnd=true;retStr=retStr+"!="+getRandBool(ttlBoolRpt,strBoolNms);}}}
retStr=retStr+"){";return retStr;}
//••••----------••••
private String getBoolExp(int ttlBoolRpt, String[] strBoolNms, int len) {
String retStr="";Random rnd=new Random();int w=0;
retStr=getRandBool(ttlBoolRpt,strBoolNms)+"=";
retStr=retStr+getRandBool(ttlBoolRpt,strBoolNms);
for(int i=0;i<len;i++){w=rnd.nextInt(5);if(w==0){
retStr=retStr+"|"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==1){
retStr=retStr+"&"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==2){
retStr=retStr+"^"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==3){
retStr=retStr+"||"+getRandBool(ttlBoolRpt,strBoolNms);}else if(w==4){
retStr=retStr+"&&"+getRandBool(ttlBoolRpt,strBoolNms);}}
retStr=retStr+";";return retStr;}
//••••----------••••
private String[] getBoolVars(int cnt) {
String[] retStr=new String[cnt];
String alpBet="abcdefghijklmnopqrstuvwxyz";
Random rnd=new Random();
for(int i=0;i<retStr.length;i++){
retStr[i]=String.valueOf(alpBet.charAt(rnd.nextInt(26)));
retStr[i]=retStr[i]+String.valueOf(alpBet.charAt(rnd.nextInt(26)));
retStr[i]=retStr[i]+String.valueOf(alpBet.charAt(rnd.nextInt(26))).toUpperCase();
retStr[i]=retStr[i]+"_"+String.valueOf(rnd.nextInt(9))+String.valueOf(rnd.nextInt(9));}
return retStr;}
//••••----------••••
private String getRandBool(int ttlBoolRpt,String[] strBoolNms){
String retStr="";String alpBt="abcdefghijklmnopqrstuvwxyz";
Random rnd=new Random();if(rnd.nextInt(66)>33){
retStr=String.valueOf(alpBt.charAt(rnd.nextInt(ttlBoolRpt)));}
else{retStr=strBoolNms[rnd.nextInt(strBoolNms.length)];}
return retStr;}
//••••----------••••


Other 20 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.