Author Topic: Help With RND Function  (Read 2774 times)

Offline markjd

  • Mc. Print
  • *
  • Posts: 7
    • View Profile
Help With RND Function
« on: 2010-Aug-28 »
Can someone help me please? I have been working through the tutorials and have started playing around with the RND function but have come across something I am unsure about.

A=RND(100)
B=RND(7)

PRINT A, 100, 100
PRINT B, 120, 120
SHOWSCREEN
MOUSEWAIT

If I run this it generates the numbers 72 and 1. If I run it again it generates 100 and 0. If I run it a third time it goes back to 72 and 1 and a forth time 100 and 0, which doesn't seem very random, what am I doing wrong?

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4147
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Help With RND Function
« Reply #1 on: 2010-Aug-28 »
Use -
Code: GLBasic [Select]
SEEDRND GETTIMERALL()
 

This gets the timer from the pc and will differ every time. Use it at the start of your program, before you call any random numbers. :)
« Last Edit: 2010-Aug-28 by Ian Price »
I came. I saw. I played.

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Help With RND Function
« Reply #2 on: 2010-Aug-29 »
Very useful information. Thanks all.