Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

random numbers

Posted on 2001-06-12
5
Medium Priority
?
151 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

618 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