ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with random numbers in gaming system (https://www.excelbanter.com/excel-programming/425013-help-random-numbers-gaming-system.html)

gtslabs

Help with random numbers in gaming system
 
I am trying to make a way to test trading systems based on a
percentage of wins and losses and points won or loss. I wrote some
code to get a random win or loss. but I need a way to add this result
to a array and not allow any more events.
so if I have 10% of the time a loss of 2 points I need to keep track
of that and not allow any more in that group once the percentage of
total is achieved.
But all the groups must be filled based on the number of attempts.

Here is my code

Sub TradeSystem()
Dim MyValue
Dim TradeCount As Integer
Dim StockPrice As Single
Dim TradeSystem(1 To 5, 1 To 2)


'trading system - set by user
'% of Trades Points won/Loss
' 10% -2
' 25% -1
' 25% +1
' 20% +2
' 10% +3
'Total 100%


TradeSystem(1, 1) = Cells(3, 5)
TradeSystem(1, 2) = Cells(3, 6)

TradeSystem(2, 1) = Cells(4, 5)
TradeSystem(2, 2) = Cells(4, 6)

TradeSystem(3, 1) = Cells(5, 5)
TradeSystem(3, 2) = Cells(5, 6)

TradeSystem(4, 1) = Cells(6, 5)
TradeSystem(4, 2) = Cells(6, 6)

TradeSystem(5, 1) = Cells(7, 5)
TradeSystem(5, 2) = Cells(7, 6)


TradeCount = 50

For I = 1 To TradeCount
Randomize
'StockPrice = (100 * Rnd) ' Generate random value between 1 and
100.


Win_Loss = Rnd
If Win_Loss < 0.5 Then
pts = -Int(2 * Rnd + 1) ' Generate Pts from -2 to -1
Result = "Loss"
' how to add this result to the group (array)?
'and not allow any more once group is full

Else
Result = "win"
pts = Int((3 * Rnd) + 1) ' Generate points from 1 to 3
' how to add this result to group (array)?
'and not allow any more once group is full
End If

Debug.Print StockPrice, pts, Result

Next I
End Sub

joel

Help with random numbers in gaming system
 
Your approach is wrong. Create a random number 0 <= x < 1.00

If random number is the following range do the following

0.00 <= X < .1 -2 10%
0.10 <= X < .35 -1 25%
0.35 <= X < .6 +1 25%
0.80 <= X < .9 -2 20%
0.90 <= X < 1.0 ? 10%

Start with a number of points like 100 and stop when you get to zero
indicating you ran out of money



"gtslabs" wrote:

I am trying to make a way to test trading systems based on a
percentage of wins and losses and points won or loss. I wrote some
code to get a random win or loss. but I need a way to add this result
to a array and not allow any more events.
so if I have 10% of the time a loss of 2 points I need to keep track
of that and not allow any more in that group once the percentage of
total is achieved.
But all the groups must be filled based on the number of attempts.

Here is my code

Sub TradeSystem()
Dim MyValue
Dim TradeCount As Integer
Dim StockPrice As Single
Dim TradeSystem(1 To 5, 1 To 2)


'trading system - set by user
'% of Trades Points won/Loss
' 10% -2
' 25% -1
' 25% +1
' 20% +2
' 10% +3
'Total 100%


TradeSystem(1, 1) = Cells(3, 5)
TradeSystem(1, 2) = Cells(3, 6)

TradeSystem(2, 1) = Cells(4, 5)
TradeSystem(2, 2) = Cells(4, 6)

TradeSystem(3, 1) = Cells(5, 5)
TradeSystem(3, 2) = Cells(5, 6)

TradeSystem(4, 1) = Cells(6, 5)
TradeSystem(4, 2) = Cells(6, 6)

TradeSystem(5, 1) = Cells(7, 5)
TradeSystem(5, 2) = Cells(7, 6)


TradeCount = 50

For I = 1 To TradeCount
Randomize
'StockPrice = (100 * Rnd) ' Generate random value between 1 and
100.


Win_Loss = Rnd
If Win_Loss < 0.5 Then
pts = -Int(2 * Rnd + 1) ' Generate Pts from -2 to -1
Result = "Loss"
' how to add this result to the group (array)?
'and not allow any more once group is full

Else
Result = "win"
pts = Int((3 * Rnd) + 1) ' Generate points from 1 to 3
' how to add this result to group (array)?
'and not allow any more once group is full
End If

Debug.Print StockPrice, pts, Result

Next I
End Sub


Bernd P

Help with random numbers in gaming system
 
Hello,

You can usse my UDF rww or redw for this:
http://www.sulprobil.com/html/distributions.html

Regards,
Bernd

gtslabs

Help with random numbers in gaming system
 
On Mar 4, 12:11*pm, Bernd P wrote:
Hello,

You can usse my UDF rww or redw for this:http://www.sulprobil.com/html/distributions.html

Regards,
Bernd


Thanks - that is great!
I am getting my critera from my worksheet.
I have the default bins set to 5.
If I only need 4 inputs but want to keep all 5 (dont want to change
formula)should I pass 0 or Null (empty cells)?
I noticed a difference in the 2 approaches

Bernd P

Help with random numbers in gaming system
 
Hello,

Hmm, there should be no difference but 0 should do it.

Send me an example with the spotted difference, please.

Regards,
Bernd


All times are GMT +1. The time now is 01:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com