# Thread: How do you assign a random number to a an integer variable

1. ## Code:
```Randomize
A = Rnd(9)
B = Rnd(9)
C = Rnd(9)
D = Rnd(9)
E = Rnd(9)
F = Rnd(9)
G = Rnd(9)
H = Rnd(9)
DoEvents```
That's what I have and all it gives me is 0 and 1  Reply With Quote

2. Code:
```Randomize(now())
A = int(Rnd *9)+1
B = int(Rnd *9)+1
C = int(Rnd *9)+1
D = int(Rnd *9)+1
E = int(Rnd *9)+1
F = int(Rnd *9)+1
G = int(Rnd *9)+1
H = int(Rnd *9)+1
DoEvents```
There ya go, hope that helps  Reply With Quote

3. Plain old Randomize will work for your first statement.  Reply With Quote

4. True true, I just like giving it a seed that isn't necessarily the same each time a random number is needed heh  Reply With Quote

5. ## Unless you're attached to your "A,B,C,etc."

You may find this code a little more efficient.
Code:
```    Dim iArray(7) As Integer
Dim iTemp As Integer

Randomize
For iTemp = LBound(iArray) To UBound(iArray)
iArray(iTemp) = Int(Rnd * 9) + 1
Next```
All the best.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•