Help with random numbers in gaming system

  • Thread starter Thread starter gtslabs
  • Start date Start date
G

gtslabs

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
 
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
 
Hello,

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

Send me an example with the spotted difference, please.

Regards,
Bernd
 
Back
Top