ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   random number generation help (https://www.excelbanter.com/excel-programming/444354-random-number-generation-help.html)

A Mad Doberman

random number generation help
 
Greetings,

I am writing an attack simulator for a game I play. In the game,
combat begins with ships on both sides attacking opposing ships at
random. Part of my program contains a 2 dimensional array where a
random number is assigned for each ship through a series of loops,
if's, select cases, etc...For the random number assignment, I am using
the code line:

ATM(ShipCount, 5) = Int((TotalDefenseShips * Rnd) + 1)

This appears to be working great and is randomly assigning numbers
througout my array, as I want. HOWEVER, I have noticed that the series
is the same with every run of the program. I need to alter my code so
the random number does not follow the same sequence, even if I don't
change any variables. With every run of my simulation, every point in
the array must have a random number assigned to it that was different
than the last simulation run.

Any ideas?

Thanks very much in advance!

GS[_2_]

random number generation help
 
A Mad Doberman has brought this to us :
Greetings,

I am writing an attack simulator for a game I play. In the game,
combat begins with ships on both sides attacking opposing ships at
random. Part of my program contains a 2 dimensional array where a
random number is assigned for each ship through a series of loops,
if's, select cases, etc...For the random number assignment, I am using
the code line:

ATM(ShipCount, 5) = Int((TotalDefenseShips * Rnd) + 1)

This appears to be working great and is randomly assigning numbers
througout my array, as I want. HOWEVER, I have noticed that the series
is the same with every run of the program. I need to alter my code so
the random number does not follow the same sequence, even if I don't
change any variables. With every run of my simulation, every point in
the array must have a random number assigned to it that was different
than the last simulation run.

Any ideas?

Thanks very much in advance!


Here's a good place to start...

http://www.cpearson.com/excel/randomNumbers.aspx

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc



Jim Cone[_2_]

random number generation help
 
You should use the "Randomize" statement on a single line before initiating a call to the Rnd
function.
Also, do not use the statement inside a loop, but place it 'outside' before the For or Do.
Multiple statements within a procedure are usually not necessary.
The later versions of Excel (2003 +) have been promoted as having better Rnd implementation.
'---
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
(List Files add-in: lists specific files/folders with hyperlinks)



"A Mad Doberman"
wrote in message
...
Greetings,

I am writing an attack simulator for a game I play. In the game,
combat begins with ships on both sides attacking opposing ships at
random. Part of my program contains a 2 dimensional array where a
random number is assigned for each ship through a series of loops,
if's, select cases, etc...For the random number assignment, I am using
the code line:

ATM(ShipCount, 5) = Int((TotalDefenseShips * Rnd) + 1)

This appears to be working great and is randomly assigning numbers
througout my array, as I want. HOWEVER, I have noticed that the series
is the same with every run of the program. I need to alter my code so
the random number does not follow the same sequence, even if I don't
change any variables. With every run of my simulation, every point in
the array must have a random number assigned to it that was different
than the last simulation run.

Any ideas?

Thanks very much in advance!




A Mad Doberman

random number generation help
 
You guys are great! Thanks to you both.


All times are GMT +1. The time now is 10:27 PM.

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