Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / I'm trying to crack a nut.. help wanted :-)

Author
Message
Monzi
20
Years of Service
User Offline
Joined: 10th May 2004
Location: Denmark
Posted: 30th Mar 2005 01:31
I'm trying to solve a problem. I want to create a bunch of numbers, from 1 to 40. But i want the numbers to be created in random order, and the same number must NOT appear twice.

My suggestion:
For X=1 to 40 step 1
NewNumber:
Number(X)=Rnd(39)+1
For Test=1 to X-1 step 1
If Number(X)=Number(test) then goto NewNumber
Next Test
Next X

But isnt there an easier way of doing it?
Underworld 1020
20
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 30th Mar 2005 01:46
This Is Probably The Shortest Way:


Same code just without using the "Step" command. "For" loops go up by increments by 1, by default, so theres no need for the "Step" command in this case. I don't see how you could write the code any shorter than what you already have .

Monzi
20
Years of Service
User Offline
Joined: 10th May 2004
Location: Denmark
Posted: 30th Mar 2005 01:53
Well Okay. I just like to keep the code as clean as possible. I didnt know about the step thingie though.

Thanks for your effort
BadMonkey91
20
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 30th Mar 2005 01:54


badmonkey'd

Badmonkey91@hotmail.com
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 30th Mar 2005 02:39


Spooky'd

Boo!
wmf
19
Years of Service
User Offline
Joined: 6th Nov 2004
Location:
Posted: 30th Mar 2005 03:30 Edited at: 30th Mar 2005 05:25


oops! I moved the print command down but I didn't remove the for next commands. here it is corrected

Login to post a reply

Server time is: 2024-09-23 15:35:16
Your offset time is: 2024-09-23 15:35:16