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 / question about keeping a variable in a numerical range

Author
Message
Phrozin
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Florida USA
Posted: 14th Apr 2005 02:55
I have a range of numbers that a variable should randomly pick from to take on as its value. My problem is the range is broken up into 3 small ranges. For example:

RANGE
12-28
122-350
400-1500

OK, how would I go about making sure the variable chooses a number in those ranges? I've started to use:

IF A = 0 AND < 12 THEN A = A + RND(12)
IF A < 122 AND > 350 THEN A = A + RND(122)

and then it hit me that I'm canceling out my previous IF statement by checking IF A = < 122. Plus it wouldn't allow the whole statement throwing out the error: "Could not determine parameter of '@$L0 AND' at line 1437.

So how would you do this, or can you even do this?

thx for any help,
Joe
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 14th Apr 2005 03:08
Your on the right track. it thoses little < > signs that make the magic work,(taken me years to learn the right way round to place them.)

Ok, so how do you use them your asking? well like this.

You said you wanted this range of numbers,

RANGE
12-28
122-350
400-1500

So you would write.

If A>12 and A<28 then A=A+ A + RND(12)

Which reads, if a is gerater than 12 and a is less than 28 then let a=a plus random number up to 12.

Some times you end up putting a -1 on the end

If A>12 and A<28 then A=A+ A + RND(12)-1

hope this helps.

In Space No One can Hear You Scream! (When your comm Line is cut?)
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 14th Apr 2005 04:58
use case like this




hope thats what you wanted.

Mentor.

PC1:XP, P4 3ghz, 1gig mem, 3x160gig hd`s, Radeon 9800pro, 6 way sound.
PC2: Linux, AMD 2ghz, 512mb ram, Nvidia GeForce4mx, 16 bit SB.
PC3: XP, laptop, intel 2.6ghz celeron, ATI 9000igp, 256mb
walkman99
19
Years of Service
User Offline
Joined: 15th Mar 2005
Location:
Posted: 14th Apr 2005 05:30
I would do it this way.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Apr 2005 05:51
Here's another way to do it. Though you need to be careful. If you have a huge overall range ( like 0 to 1,000,000), but only a few small valid ranges, this could get slow. This is also distributed evenly based on the individual ranges within the overall range. Mentor's code does work, but has an even 1/3rd chance of being in any given range regardless of the size (not knocking your code Mentor). Of course - it all depends on what you are trying to accomplish. There are uses for both Mentor's code and this code.



"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Phrozin
21
Years of Service
User Offline
Joined: 16th Jun 2003
Location: Florida USA
Posted: 15th Apr 2005 02:15
@HowDo - answered what my next question was going to be, I forgot the computer starts counting from 0, so I had to add +1 to all my random statements.

@ Mentor,Walkman99,RiiDii - they all worked! I'm not used to having multiple approaches to a problem. Now I just have to use all three to see which one is best suited to the task.

Many many thanks to all four of you,
I honestly thought I had hit a wall on this one.

Joe
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 15th Apr 2005 22:54
One other thing when you get your program up and running don't forget to put randoize seed at the begin, other wize the same thing happenes each time its run.

In Space No One can Hear You Scream! (When your comm Line is cut?)
Vixen
19
Years of Service
User Offline
Joined: 6th Apr 2005
Location: Netherlands
Posted: 16th Apr 2005 03:25
Yeah, I believe that's RANDOMIZE TIMER

Trying to help where I can [Newbie status ]

Login to post a reply

Server time is: 2024-09-23 17:26:40
Your offset time is: 2024-09-23 17:26:40