Javascript percentage of winning algorithm
up vote
-1
down vote
favorite
I have a slots machine game HTML5 + Javascript.
I have found the below algoritm on Stackoverflow, but i need another percentage
this.d = Math.random();
if (this.d < 0.3333) {
this.nextSymbols = [
['320', '320', 'jackpot'],
['jackpot', '320', '400'],
['320', '320', 'jackpot'],
];
} else if (this.d < 0.005) {
this.nextSymbols = [
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
];
} else {
this.nextSymbols = [
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
];
}
I need to have:
1 of 3 spins to be a winning prize 2
1 of 200 spins wins big prize
Any math expert advice would be much appreciate.
Thanks
javascript algorithm
add a comment |
up vote
-1
down vote
favorite
I have a slots machine game HTML5 + Javascript.
I have found the below algoritm on Stackoverflow, but i need another percentage
this.d = Math.random();
if (this.d < 0.3333) {
this.nextSymbols = [
['320', '320', 'jackpot'],
['jackpot', '320', '400'],
['320', '320', 'jackpot'],
];
} else if (this.d < 0.005) {
this.nextSymbols = [
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
];
} else {
this.nextSymbols = [
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
];
}
I need to have:
1 of 3 spins to be a winning prize 2
1 of 200 spins wins big prize
Any math expert advice would be much appreciate.
Thanks
javascript algorithm
1
How is "I have 10 big prizes" relevant for the probability of a single spin?
– Bergi
Nov 19 at 22:04
2
Hint: 1/3 =0.3333…
, 1/200 =0.005
(compared to 50% =0.5
, 20% =0.2
in the existing code)
– Bergi
Nov 19 at 22:05
@Bergi thanks. I figured out
– PixelArtie
Nov 19 at 22:21
1
<
means less than. Soif (this.d < 0.005)
means that the value is less than 0.005. Any value where that is the case is also less than 0.3333. However the if-test for <0.005 is in theelse
clause of the <0.3333, so nobody will ever win the big prize.
– Richardissimo
Nov 19 at 22:39
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a slots machine game HTML5 + Javascript.
I have found the below algoritm on Stackoverflow, but i need another percentage
this.d = Math.random();
if (this.d < 0.3333) {
this.nextSymbols = [
['320', '320', 'jackpot'],
['jackpot', '320', '400'],
['320', '320', 'jackpot'],
];
} else if (this.d < 0.005) {
this.nextSymbols = [
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
];
} else {
this.nextSymbols = [
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
];
}
I need to have:
1 of 3 spins to be a winning prize 2
1 of 200 spins wins big prize
Any math expert advice would be much appreciate.
Thanks
javascript algorithm
I have a slots machine game HTML5 + Javascript.
I have found the below algoritm on Stackoverflow, but i need another percentage
this.d = Math.random();
if (this.d < 0.3333) {
this.nextSymbols = [
['320', '320', 'jackpot'],
['jackpot', '320', '400'],
['320', '320', 'jackpot'],
];
} else if (this.d < 0.005) {
this.nextSymbols = [
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
['320', 'jackpot', '400'],
];
} else {
this.nextSymbols = [
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
[Symbol.random(), Symbol.random(), Symbol.random()],
];
}
I need to have:
1 of 3 spins to be a winning prize 2
1 of 200 spins wins big prize
Any math expert advice would be much appreciate.
Thanks
javascript algorithm
javascript algorithm
edited Nov 19 at 22:07
asked Nov 19 at 21:59
PixelArtie
23
23
1
How is "I have 10 big prizes" relevant for the probability of a single spin?
– Bergi
Nov 19 at 22:04
2
Hint: 1/3 =0.3333…
, 1/200 =0.005
(compared to 50% =0.5
, 20% =0.2
in the existing code)
– Bergi
Nov 19 at 22:05
@Bergi thanks. I figured out
– PixelArtie
Nov 19 at 22:21
1
<
means less than. Soif (this.d < 0.005)
means that the value is less than 0.005. Any value where that is the case is also less than 0.3333. However the if-test for <0.005 is in theelse
clause of the <0.3333, so nobody will ever win the big prize.
– Richardissimo
Nov 19 at 22:39
add a comment |
1
How is "I have 10 big prizes" relevant for the probability of a single spin?
– Bergi
Nov 19 at 22:04
2
Hint: 1/3 =0.3333…
, 1/200 =0.005
(compared to 50% =0.5
, 20% =0.2
in the existing code)
– Bergi
Nov 19 at 22:05
@Bergi thanks. I figured out
– PixelArtie
Nov 19 at 22:21
1
<
means less than. Soif (this.d < 0.005)
means that the value is less than 0.005. Any value where that is the case is also less than 0.3333. However the if-test for <0.005 is in theelse
clause of the <0.3333, so nobody will ever win the big prize.
– Richardissimo
Nov 19 at 22:39
1
1
How is "I have 10 big prizes" relevant for the probability of a single spin?
– Bergi
Nov 19 at 22:04
How is "I have 10 big prizes" relevant for the probability of a single spin?
– Bergi
Nov 19 at 22:04
2
2
Hint: 1/3 =
0.3333…
, 1/200 = 0.005
(compared to 50% = 0.5
, 20% = 0.2
in the existing code)– Bergi
Nov 19 at 22:05
Hint: 1/3 =
0.3333…
, 1/200 = 0.005
(compared to 50% = 0.5
, 20% = 0.2
in the existing code)– Bergi
Nov 19 at 22:05
@Bergi thanks. I figured out
– PixelArtie
Nov 19 at 22:21
@Bergi thanks. I figured out
– PixelArtie
Nov 19 at 22:21
1
1
<
means less than. So if (this.d < 0.005)
means that the value is less than 0.005. Any value where that is the case is also less than 0.3333. However the if-test for <0.005 is in the else
clause of the <0.3333, so nobody will ever win the big prize.– Richardissimo
Nov 19 at 22:39
<
means less than. So if (this.d < 0.005)
means that the value is less than 0.005. Any value where that is the case is also less than 0.3333. However the if-test for <0.005 is in the else
clause of the <0.3333, so nobody will ever win the big prize.– Richardissimo
Nov 19 at 22:39
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
To summarize - as @Bergi and @Richardissimo written in comments.
1 / 3 is 0.(3), but you can just write thid.d < 1/3
interpreter will calculate it for you.
And if you are making else if
the second case will never fire. You have to change the order of conditions.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
To summarize - as @Bergi and @Richardissimo written in comments.
1 / 3 is 0.(3), but you can just write thid.d < 1/3
interpreter will calculate it for you.
And if you are making else if
the second case will never fire. You have to change the order of conditions.
add a comment |
up vote
0
down vote
To summarize - as @Bergi and @Richardissimo written in comments.
1 / 3 is 0.(3), but you can just write thid.d < 1/3
interpreter will calculate it for you.
And if you are making else if
the second case will never fire. You have to change the order of conditions.
add a comment |
up vote
0
down vote
up vote
0
down vote
To summarize - as @Bergi and @Richardissimo written in comments.
1 / 3 is 0.(3), but you can just write thid.d < 1/3
interpreter will calculate it for you.
And if you are making else if
the second case will never fire. You have to change the order of conditions.
To summarize - as @Bergi and @Richardissimo written in comments.
1 / 3 is 0.(3), but you can just write thid.d < 1/3
interpreter will calculate it for you.
And if you are making else if
the second case will never fire. You have to change the order of conditions.
answered Nov 19 at 23:25
Konowy
320420
320420
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383239%2fjavascript-percentage-of-winning-algorithm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
How is "I have 10 big prizes" relevant for the probability of a single spin?
– Bergi
Nov 19 at 22:04
2
Hint: 1/3 =
0.3333…
, 1/200 =0.005
(compared to 50% =0.5
, 20% =0.2
in the existing code)– Bergi
Nov 19 at 22:05
@Bergi thanks. I figured out
– PixelArtie
Nov 19 at 22:21
1
<
means less than. Soif (this.d < 0.005)
means that the value is less than 0.005. Any value where that is the case is also less than 0.3333. However the if-test for <0.005 is in theelse
clause of the <0.3333, so nobody will ever win the big prize.– Richardissimo
Nov 19 at 22:39