?
Solved

random numbers

Posted on 2001-06-12
5
Medium Priority
?
147 Views
Last Modified: 2010-03-05
I need to generate a random number from 1 to 15 with one condition: it can not be any of the numbers listed on @alreadyusedbanners!!!
0
Comment
Question by:superquestions
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 8

Expert Comment

by:bebonham
ID: 6183801

@alreadyusedbanners=(4,3,7,1);
for(1..15){$numbs{$_}=$_};
foreach(@alreadyusedbanners){delete $numbs{$_}};
@keys=keys %numbs;
$id=rand($#keys);
print $numbs{$keys[$id]} . "\n";
















0
 
LVL 84

Expert Comment

by:ozo
ID: 6184449
#You probably meant
print $keys[rand(@keys)]
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6185787
yeah, that is better, and if we aren't going to use the hash, in the end, lets just avoid it because it is slower and takes more memory than an array I think.

@alreadyusedbanners=(4,3,7,1);
NUMBER: for(1..15){
foreach $used(@alreadyusedbanners){next NUMBER if $_==$used};
push(@keys, $_)};
print $keys[rand(@keys)];


Bob
0
 
LVL 8

Accepted Solution

by:
bebonham earned 300 total points
ID: 6200454
my previous posts have answered the question.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6200906
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question