Author Topic: RANDOM Numbers  (Read 2304 times)

AnonymousPostings

  • Newbie
  • *
  • Posts: 49
RANDOM Numbers
« on: July 01, 2010, 06:33:09 AM »
Hello, Whilst using HyperNext Creator Software this afternoon, I think there maybe a bug with the "Random Number Generator" (Which selects a random number between a range of two main numbers). The line/code:
 
Put RndFN(NUMBER1,NUMBER2) into VARIABLE1
 
Is the line I beleive has the fault as it generates the same numbers over and over.
 
For example, if I had a button, in my application that when pressed, performed certain actions, and it's coding was for example:
 
\\\CODE\\\\
Put RndFN(100,150) into field 1
\\\CODE\\\\\
 
(In other words, Select a random number between 100 and 150)
 
However when It is pressed, it might say for example generate: 108 and each time the button is pressed, as expected, generates a random number 135 then 136 ECT. and puts the new data into the field. Which all seems well and good. However, the numbers aren't random!
If you close the application and re-run it, the same number sequence is generated! 108, 135, 136 and so on.
 
The thing is, it appears the numbers are following a pre-coded protocol and aren't random. If you try entering/copying and pasting that example line into a button on your own version of your software, I can almost guarantee each time the button is pressed, it will first generate; 108 then press again, 135, 136 ect. ect. and so on. This isn't a good point, and when you actually need a random number and not guessable or predicted ones, it's not that good. 
 
Thankyou for your time,
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 405
  • Here to help you
Re: RANDOM Numbers
« Reply #1 on: July 01, 2010, 06:36:21 AM »
Thank you for your query on the random number generator.

By default the generated numbers are repeatable as this can help to debug your program.

However, you can change the random seed so that they give a completely different set of  numbers:-

Code: [Select]
    SetSeed(300)
this will give one set of repeatable numbers, but using 500 would give another set of repeatable numbers.


or with and unknown seed - the time (ticks since computer started)

Code: [Select]
    Local tm

    Put TicksFN into tm

    SetSeed(tm)
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

 

anything