Dear all ,
Please help me out
From the following code i want groups of six random no. which total of services must be in between 840 - 900
But problem is that i am getting repeating random No. & that is i don want
as well as all the random no. use....
Help me out thanks in advance
#!/usr/bin/perl -w my @new_lot = qw(1 .. 186); my @A_services =qw(121 182 111 160 105 113 121 97 123 157 133 161 141 +135 137 145 133 137 151 118 126 141 174 181 154 109 198 114 122 162 9 +1 99 116 122 195 199 150 192 163 88 112 157 182 210 124 105 144 166 144 257 164 156 173 + 154 193 142 143 126 118 130 107 86 131 154 131 147 134 118 115 135 141 158 129 + 143 126 128 134 129 167 130 135 117 127 146 96 117 99 99 139 152 149 136 105 1 +24 136 160 160 139 177 115 123 103 150 183 132 171 121 114 111 113 131 144 122 14 +1 111 139 145 109 114 122 103 160 153 147 172 155 122 296 124 112 161 124 311 99 + 157 122 120 198 152 140 162 177 98 138 156 177 103 180 187 173 150 135 168 132 + 196 112 195 126 113 116 105 116 151 216 188 158 121 166 148 132 89 197 92 115 +98 130 103 120 261 143 126 167 203 95 165 129); my @only_unique = (); my $index1 = scalar(@new_lot); my $dd = 0; for(my $o = 0;$o<6;$o++){ my $one1 = int(rand($index1)); if($one1 == 0){$one1 = int(rand($index1));} for(my $four = 0;$four <scalar(@only_unique);$four++){ if($only_unique[$four]== $one1){ $dd++; } } if($dd == 0){ push(@only_unique,$one1); } } my $tt = 0; for (my $p = 0;$p<scalar(@only_unique);$p++){ my $two = $only_unique[$p]; $tt = $tt+$A_services[$two-1]; } my $gurilla = scalar(@only_unique); if($gurilla == 6){ if(($tt <900) && ($tt > 840)){ for(my $iq= 0;$iq< $index1;$iq++){ &is_exist(); } } } sub is_exist(){ my $Tot = 0; my $y = 0;@Ram = (); for(my $h = 0;$h<6;$h++){ my $one = int(rand($index1)); if($one == 0){$one = int(rand($index1));} for(my $dear = 0;$dear <scalar(@only_unique);$dear++){ if($only_unique[$dear] == $one){ $one = int(rand($index1)); if($one == 0){$one = int(rand($index1));} redo; } #$Tot = $Tot + $A_services[$_]; } push(@Ram,$one); } for(my $no = 0 ; $no<scalar(@Ram);$no++){ my $tw = $Ram[$no]; $Tot = $Tot + $A_services[$tw-1]; } if($y == 0){ if(($Tot >840) && ($Tot <900)){ for(my $pune = 0;$pune <scalar(@Ram); $pune++){ push(@only_unique,$Ram[$pune]); } } } } my $total = 0; my $s = int(rand(100)); $file_name = "bha.txt"; open(FH,">$file_name"); my $jogi = 0; for(my $k = 0;$k <scalar(@only_unique);$k++){ my $lol = ""; my $ganesh = $only_unique[$k]; $total = $total+$A_services[$ganesh-1]; if($jogi == 5){$jogi = -1 ; $lol = "__Total: $total "."\n"; $total = 0; } else{$lol = "";} #my $ganesh = $only_unique[$k]; #$total = $total+$A_services[$ganesh-1]; print FH $cat_one[$ganesh-1]."--".$only_unique[$k]."--".$A_service +s[$ganesh-1]." ".$lol; print "$k><$jogi> ".$cat_one[$ganesh-1]."--".$only_unique[$k]."--" +.$A_services[$ganesh-1]." ".$lol; $jogi++; #if($jogi == 5){$jogi= 0;} } close FH; print "\n\n"; my $t5 = 1; foreach (@only_unique){ print $_," "; $t5++; } print "\n";

In reply to Help Me in following code :: by gskoli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.