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

There are several ways to interpret that.

One way is that you want: groups of six randomly chosen, unique (positive) integers that sum to between 840 - 900 (inclusive?). Here is a sub that will do that:

#! perl -slw use strict; use List::Util qw[ sum ]; sub nUniqRandsSumTo { my( $n, $target ) = @_; ## Prevent infinite loop. die 'No solution' if ( ( $n * ($n-1) ) / 2 ) > $target; my @rvs; { @rvs = $target; while( @rvs < $n ) { ## pick an element at my $i = int rand @rvs; ## Can't split 0, 1, 2 into two unique values redo if ( my $toSplit = $rvs[ $i ] ) < 3; my $first = int( rand $toSplit ); my $second = $toSplit - $first; ## try again if it split into two equal values redo if $first == $second; ## replace the original with the random pair splice @rvs, $i, 1, $first, $second; } my %seen; ## Do it all from scratch if we got dups ## Can be expensive if the target is close to the limit redo if grep{ ++$seen{ $_ } > 1 } @rvs; } return @rvs; } for( 1 .. 10 ) { my $target = 840 + int( rand 61 ); my @rands = sort{ $a <=> $b } nUniqRandsSumTo( 6, $target ); printf "sum: %3d [ %s ]\n", sum( @rands ), "@rands"; } __END__ c:\test>834245.pl sum: 896 [ 0 27 34 162 197 476 ] sum: 889 [ 35 77 109 179 196 293 ] sum: 878 [ 18 23 77 91 280 389 ] sum: 885 [ 6 37 68 136 154 484 ] sum: 854 [ 7 8 12 70 237 520 ] sum: 899 [ 8 10 29 101 293 458 ] sum: 858 [ 0 28 37 52 367 374 ] sum: 887 [ 1 8 11 22 43 802 ] sum: 899 [ 11 64 65 117 271 371 ] sum: 872 [ 7 14 40 43 154 614 ]

The way it works is it picks a target between 840 & 900 and then calls the sub with N (6) and the chosen target.

The sub:

  1. Places the target in an array.
  2. Loops while the size of the array is less than N.
  3. Picks one of the values in the array at random and splits it randomly into 2 values that add up to the original.
  4. Checks for dups and starts again if it has any.

Other possible interpretations include:


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

In reply to Re: Help Me in following code :: by BrowserUk
in thread 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.