Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with random numbers!

Status
Not open for further replies.

Quijian

ISP
Jul 9, 2004
32
US
I am having problems randomizing some numbers. I am using the Randomize without any parameters and then I am using the Rnd functions in a equation. Here is the snippet:

Randomize
cardvalue = Int(14 * Rnd) + 1)

It keeps on giving me the same values each time I run it. I will glady take any solutions. Thanks guys!
 
Interesting.
I assume the parentheses at the end of the code you supplied is superfluous, and not in the actual code.

If your code is correct and you're still not getting any value, try seeding the Randomize statement with the current datetime stamp.

[tt]Randomize (Now)
cardvalue = Int(14 * Rnd) + 1[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
No wait a minute...They were different values but I ran it again I got a the exact same answer...sorry...
 
You mean for example you ran it, got 10,7,4,13,2,7 as random numbers, then ran it again and got 10,7,4,13,2,7 as random numbers?

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
In testing Randomize (Now) It doesn't appear that the it uses the full precision of the timestamp. Because if I run it over and over again, I get the same number (just doing a debug.print Rnd). However, If I change my clock by an hour I get a different number.

 
Yeah, it was just an idea I was throwing around...

Quijian - check out this post: thread222-813668. There are a few solutions in there that will most likely help you out.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top