Qbasicnews.com January 26, 2020, 06:04:16 PM  Pages: Author Topic: A new random generator  (Read 2898 times)
Smurfy
New Member

Posts: 11 « on: February 20, 2008, 05:09:30 PM »

Well, I need to come up with another random number generator. Here's the one I have.
Code:
CLS
INPUT "How many random numbers would you like to generate"; X
DIM A(X) AS INTEGER
FOR C = 1 TO X
A(C) = C
NEXT C
RANDOMIZE TIMER
FOR SWITCH = 1 TO 10
FOR C = 1 to X
B = INT(X * RND (1) + 1)
SWAP A(C), A(B)
NEXT C
NEXT SWITCH
FOR C = 1 TO X
PRINT A(C)
NEXT C
PRINT
OPEN "rnd.csv" FOR OUTPUT AS #1' This just makes it so you can put it in a spreadsheet and test it for no repeats"
FOR D = 1 TO X
PRINT #1, A(D)
NEXT D
CLOSE #1
but I need one that takes two arrays and you leave one unpopulated for now but with the other you generate a random number lets say five you assign that to position one in array A and in array B you go over to the fifth position and change the zero there to a one, then you generate a seven and you assign that to position two in array A and in array B you change the zero in the seventh position to a one and so on, and if you generate a random number in Array A that has already come up and its position in array b is assigned a one instead of a zero you erase that number from array A and reassign it with a new number. i need this one so i can compare the two to see which one  is more random. I got the other one pretty easily but  I don't quite know how to start this one
 « Last Edit: February 26, 2008, 02:58:20 PM by Smurfy » Logged
Mac
Senior Member  Posts: 243  « Reply #1 on: March 05, 2008, 08:07:27 AM »

I don't quite know how to start this one
Code:
CLS
INPUT "How many random numbers would you like to generate"; X
DIM A(X) AS INTEGER
DIM B(X) AS INTEGER
FOR C = 1 TO X
N = 1 + INT(RND * X)
PRINT N
NEXT C

Then replace PRINT N to code which does what you said.

Mac Logged
Smurfy
New Member

Posts: 11 « Reply #2 on: March 05, 2008, 10:42:06 AM »

Thank you, I'll see where that takes me. Logged
 Pages: