public static list<instsec> setdatasec (list<string> instno) {list<instsec> result = new arraylist< Instsec> (); String[] Mon ={"2014-01", "2014-02", "2014-03", "2014-04"};int[] flag ={1,2,3,4,5}; list<string> instnosub5 = new arraylist<string> (); for (int i=0;i<instno.size (); i++) {if (! Instnosub5.contains (Instno.get (i). substring (0,5))) {Instnosub5.add (Instno.get (i). substring (0,5));}} For each organvalue, there are five levels per month, corresponding to flag propfor (int i=0;i<instnosub5.size (); i++) {for (int j=0;j<mon.length;j++) { float[] prop = Genprop ();//Note: A random probability is generated here for (int k=0;k<flag.length;k++) {instsec inst=new instsec (); inst.setinst_no_ SUB5 (Instnosub5.get (i)); Inst.setsa_tx_m (Mon[j]); Inst.setflag (Flag[k]); Inst.setprop (Prop[k]); Result.add (inst);}} return result;} public static float[] Genprop () {//Generate probabilistic random number, and let and for 1float[] prop =new float[5];int[] randint =new int[5];int sum=0;for (int i=0 ; i<5;i++) {randint[i]=1+ (int) (Math.random () *10); sum+=randint[i];}
DecimalFormat df=new DecimalFormat (". xx"), float sumprop=0;for (int i=0;i<5;i++) {prop[i]= float.parsefloat ( Df.format (1.0*randint[i]/sum));//system.out.println ("Prop is" +prop[i]); sumprop+=prop[i];} System.out.println ("Sumprop is" +sumprop) sumprop=float.parsefloat (Df.format (Sumprop)); if (sumprop<1) prop[4] +=1-sumprop;elseprop[4]-=sumprop-1;//system.out.println ("prop[4] is" +prop[4]); return prop;}
Note: The subscript for arguments to SQL is starting from 1, and the Java substring method starts with 0
Java: Generates a random probability of 2 decimal digits, making the and 1