# Check if number == rnd

## Recommended Posts

```local z1 = 10
local rnd1, rnd2, rnd3 = gR()
local zahl = 0
if ( tonumber ( z1 ) == tonumber ( rnd1 ) ) or ( tonumber ( z1 ) == tonumber ( rnd2 ) ) or ( tonumber ( z1 ) == tonumber ( rnd3 ) ) then
zahl = zahl + 1
else
outputChatBox("Zahl 1: Falsch!")
end
```

gR():

```local rnd1 = math.random ( 1, 12 )
local rnd2 = math.random ( 1, 12 )
local rnd3 = math.random ( 1, 12 )
return rnd1, rnd2, rnd3
```

Hey^^

I try to check if one of the random numbers is the same like z1.

But even if it is the same,it outputs "Zahl 1: Falsch!".

I tried to output rnd1, rnd2, rnd3 and z1 and this works.

```local z1 = 10
local rnd1, rnd2, rnd3 = gR()
local zahl = 0
if ( (tonumber ( z1 ) == tonumber ( rnd1 ))  or ( tonumber ( z1 ) == tonumber ( rnd2 ) ) or ( tonumber ( z1 ) == tonumber ( rnd3 ) )) then
zahl = zahl + 1
else
outputChatBox("Zahl 1: Falsch!")
end
```

Try this.

Edited by Guest

I don't understand you, random numbers may not be 10 lol

I don't even know why you do need to check if a random number is 10.

@Stanley you didn't change anything..

@Draken

I generate a number between 1 and 12. And I want to check if one of those randoms is 10.

It is for a lottery to check how many right numbers he picked.

simply :

```
function gr()
return math.random ( 1, 12 )
end

function something()
local someotherthing = 10
local someanotherthing = 0
for i=1,3 do
local random = gr()
if someotherthing == random then
someanotherthing = someanotherthing + 1
else
outputChatBox("Whatever is it , Falsch!")
end
end
end

```

I tested it right now on Lua Command Line and it worked perfectly.

Basically, same code:

```function gR( )
return math.random ( 1, 12 ), math.random ( 1, 12 ), math.random ( 1, 12 );
end

function test ( )
local z1 = 10;
local rnd1, rnd2, rnd3 = gR( );
local zah1 = 0;
print ( rnd1, rnd2, rnd3 );
if ( tonumber ( z1 ) == tonumber ( rnd1 ) or tonumber ( z1 ) == tonumber ( rnd2 ) or tonumber ( z1 ) == tonumber ( rnd3 ) ) then
zah1 = zah1 + 1;
print ( 'You won \$250.000.000!' );
else
print ( 'Zah1 1: Falsch!' );
end
end

--[[

First try:

test( );

Output:

1   7   3
Zah1 1: Falsch!

--

Second try:

test( );

Output:

10  8   6
You won \$250.000.000!

--

]]
```

As you can see, it worked perfectly. I don't understand your problem.

@Stanley you didn't change anything..

@Draken

I generate a number between 1 and 12. And I want to check if one of those randoms is 10.

It is for a lottery to check how many right numbers he picked.

Yes, I did. Look at line 4. I added a "(". Look at your code and will see why I added this.

@Stanley but you forgot to add the ")". And this doesn't change anything @Draken I also don't understand this problem. My code should work fine, but it doesn't.

I have 3 numbers (z1,z2,3) and I check it like this:

```
if ( tonumber ( z1 ) == tonumber ( rnd1 ) or tonumber ( z1 ) == tonumber ( rnd2 ) or tonumber ( z1 ) == tonumber ( rnd3 ) ) then
zahl1 = zahl1 + 1;
print ( 'You won \$250.000.000!' );
else
print ( 'Zah1 1: Falsch!' );
end
if ( tonumber ( z2 ) == tonumber ( rnd1 ) or tonumber ( z2 ) == tonumber ( rnd2 ) or tonumber ( z2 ) == tonumber ( rnd3 ) ) then
zahl1 = zahl1 + 1;
print ( 'You won \$250.000.000!' );
else
outputChatBox( 'Zahl 2: Falsch!' );
end
if ( tonumber ( z3 ) == tonumber ( rnd1 ) or tonumber ( z3 ) == tonumber ( rnd2 ) or tonumber ( z3 ) == tonumber ( rnd3 ) ) then
zahl1 = zahl1 + 1;
outputChatBox( 'You won \$250.000.000!' );
else
outputChatBox( 'Zahl 3: Falsch!' );
end

```

But it simply doesn't work I tested it and it's working.

```zahl1 = 0;
z1 = 10;
z2 = 10;
z3 = 10;
rnd1 = math.random ( 1, 12 );
rnd2 = math.random ( 1, 12 );
rnd3 = math.random ( 1, 12 );

if ( z1 == rnd1 or z1 == rnd2 or z1 == rnd3 ) then
zahl1 = zahl1 + 1;
print ( 'You won \$250.000.000!' );
else
print ( 'Zah1 1: Falsch!' );
end
if ( z2 == rnd1 or z2 == rnd2 or z2 == rnd3 ) then
zahl1 = zahl1 + 1;
print ( 'You won \$250.000.000!' );
else
print( 'Zahl 2: Falsch!' );
end
if ( z3 == rnd1 or z3 == rnd2 or z3  == rnd3 ) then
zahl1 = zahl1 + 1;
print( 'You won \$250.000.000!' );
else
print( 'Zahl 3: Falsch!' );
end

```

My numbers (z1, z2, z3) are selected from the database. I think the problem was there, because it works now (without changing anything now oO)

• MTA Team

Why does it have to be so difficult and hardcored script?

```local winner = 10

function(player, cmd)
local random = tonumber(math.random(1,12))
if random == winner then
outputChatBox("You won, congratulations.", player, 0, 255, 0, false)
else
outputChatBox("Better luck next time.", player, 255, 0, 0, false)
end
end
)

```

Done.

I already got it In my script it was so difficult, because there were 3 numbers and 3 randoms. And I had to check if one of the randoms contains one of my numbers.

## Create an account

Register a new account