Qbasicnews.com
November 13, 2019, 07:25:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: A new random generator  (Read 2846 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


WWW
« 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: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!