All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
9 random digits (Posted on 2003-05-02) Difficulty: 3 of 5
Suppose you want to make a random 9 digit number, using every number from 1 to 9 exactly once. You have a process called random(top) that gives a random number up to top (if top was 5, it would give random numbers from 1 to 5)

a) How could you do this?

b) If top couldn't be more than 9, how could you do this using random(top) only 9 times (or less)?

See The Solution Submitted by Gamer    
Rating: 3.4000 (5 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re: Do it with 1 invocation of random as follows | Comment 18 of 20 |
(In reply to Do it with 1 invocation of random as follows by Troy Bull)

Troy wrote:
my $number = 99999999
my $r = random(900000000)

my $randomString = $number + $r


Sorry, but this doesn't guarantee that each digit is used once.
  Posted by SilverKnight on 2003-09-09 23:29:28

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (11)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information