Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random numbers
#1
hope someone could help
looking to generate random numbers from 0-9
my problem is they come up the same and i could never get the 0 to show up
Reply
#2
(10-20-2007, 09:28 PM)MN link Wrote:looking to generate random numbers from 0-9

randomize timer
for i=1 to 50: print int(rnd*10);: next i: print

This will generate 50 random numbers and the series will be different the next time you run the program because of the randomize timer statement at the beginning of the program.

But note also that by the nature of random numbers, I could theoretically generate all 50 and not get a 0 or a 7 or any other given digit. It is a bit like flipping a coin: you could get 50 heads.

If what you want is all 10 digits, 0-9, in random order with each digit appearing exactly once, ask again. That is a different technique.

Mac
Reply
#3
'Namely
DIM d(9) AS INTEGER: FOR i = 1 TO 9: d(i) = i: NEXT i
RANDOMIZE TIMER
FOR shuffle = 1 TO 5' Just shuffling 5 times. Could be any number."
  FOR i = 0 TO 9
    r = INT(RND * 10)' A random number 0 to 9
    SWAP d(i), d®
  NEXT i
NEXT shuffle
FOR i = 0 TO 9: PRINT d(i); : NEXT i: PRINT

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)