PDA

View Full Version : Since when does MAX mean LESS THAN?


RecoJohnson
11-07-2011, 07:45 PM
Alice is really frustrating to work with because of simple non-logical elements like this...

http://i.imgur.com/7xwOI.jpg

Powerhouse64
11-07-2011, 07:56 PM
You sir seem to just be unfortunately unlucky! I just plugged that same program into Alice and got a satisfactory spread of numbers! Alice just didn't pick four for a bit for you apparantly!

x2495iiii
11-07-2011, 08:16 PM
I've had the same thing happen to me before. I think it was a bug that was fixed in the updates.

I don't suppose your copy of Alice is old?

Mr Kidnapper
11-07-2011, 11:45 PM
Less of a bug and more of an off-by-one error. See, when programming people tend to make lots of off-by-one's, especially when concerning inequalities. They're really hard to find because they don't generate an error, and are somewhat hard to find under a massive stack of code. Likely all the guy had to do was change the operator for the max random number from < to <=.

aikmin
11-08-2011, 01:59 AM
This is not a bug. Random number returns a Double value between 0 and 1 (not including 1). For minimum, Alice simply add the "min value" to the generated number. For maximum, Alice multiply the "max value" with the generated number.

Note: This is not something Alice made up.

Edit: "integerOnly==true" returns the int of the Double value and not the Round to prevent you from getting 1.

random number min=0, max=1, integerOnly=true always return 0

0.12 returns 0
0.55 also returns 0
0.99 also returns 0

By definition of the Random number [ min, max ).

RecoJohnson
11-08-2011, 06:14 PM
@aikmin

So how exactly is a number calculated?
I tried what you said :
http://i.imm.io/blMw.jpeg


@Mr Kidnapper - Not really a bug but a programming error I agree.
But.. doesn't bug == programming error?

@x2495iiii I am using Alice 2.2, and I have the latest version of Java installed.

@Powerhouse64 can you post a screenshot? I want to see this :o

legolizard
11-08-2011, 08:59 PM
This is not a "bug." In most programming languages the start of something is not '1' it is '0'

So at the moment disregard the minimum value and assume it is 0. So your maximum is whatever you want say 6. So you can get 0 , 1 , 2 , 3 , 4 , and 5. Now count how many numbers that is. 6 The maximum really specifes how many numbers you can display starting with 0. That is why it is a bit odd. :)

Let's take your first example.

Min : 1
Max : 4

However remember that the computer starts with 0 so instead make it :

Min : 0
Max : 4

So what you would be able to display 0 , 1 , 2 , 3. Note how we have 4 numbers. But wait we have a problem your output did not show 0.:eek::eek:

So this is what I think Alice does. It finds the numbers we just found above and then uses the minimum value to determine how many of those it should display. In your case since you specified 1 it would display 4 - 1 or 3 different numbers. Them being 1 , 2 , and 3.

Hope that is not too confusing. :)