Author Topic: Rnd function  (Read 9082 times)

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Rnd function
« on: February 25, 2005, 04:56:56 PM »
Yes, The Visual Basics Rnd function after a period of time produces repeating data?

Any one know a soultion to this?

We can use the rnd function in combination with another really clever way to generate numbers. ex:
An example of a way will be to mesure the uncertainty of the processor and the system timer interacting and/or then uncertainty of the processor and the hard drive interacting
The ultimate source for random information will be the internet but who is going to bother with a system of collecting that information or with running DB only when pc is online.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2554
    • View Profile
    • http://kuro-tejina.com
Rnd function
« Reply #1 on: February 25, 2005, 05:00:26 PM »
Try

"randomize timer"

before each rnd event

This will pretty much never produce a repeating sequence as the seed number is always inherantly changing.

 :D  PY  :D
There are 10 kinds of people in the world

Those who understand binary.

and those who don't

:D PY :D

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Rnd function
« Reply #2 on: February 25, 2005, 05:12:07 PM »
ok I will , There is a limit on how mutch "time numbers" the program understands though

To make it even better we can make it
Quote
Timer + Val(Replace(Date, "/", ""))

thanks for your help PY

But I already use "randomize" witch basicaly means "randomize timer" in my code

Here is an idea

Quote
Private Sub Form_Load()
Randomize Timer + Val(Replace(Date, "/", ""))
MsgBox Rnd(-(Timer + Rnd))
End Sub

The confusion here is:

Lets say A is not the same number over time:
Does "Randomize A" get compiled by visual basic by converting it into
 "Rnd(-abs(A))" on each rnd call? or somthing close to that?
« Last Edit: February 25, 2005, 05:24:46 PM by Botsareus »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7709
    • View Profile
Rnd function
« Reply #3 on: February 25, 2005, 05:41:41 PM »
Bots, found a gaussian curve online from that online book I showed you.  It's in C, but it isn't hard to convert it to VB.

I can't paste it here because of formatting issues, and the fact that the source is a PDF, and cause I'm lazy.  But here is the section its in.  Search for gasdev.  It's at the very end.



Are we talking about the period of a random number function here?

Everyone wanting to discuss this read this introduction and this section on the basics of random number generation.

Basically, a computer can't produce random numbers.  Well, not unless you attach a geiger counter to it and generate random bits based on that.  The only source of truly random stuff is nature.  But for most purposes the random number generators of a computer are good enough.

The above articles are written for C standard (my favorite language! :P :ph43r:), but you can probably figure out what's going on without too much trouble.  Everything it talks about are just as true for VB as for and C compiler.
« Last Edit: February 25, 2005, 05:42:48 PM by Numsgil »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Rnd function
« Reply #4 on: February 25, 2005, 05:51:21 PM »
Thanks but its just even more confusion; I have not even learned Precalcules; And AAAAAAAAA! C~!~~!~  <_<

Can  some one just give me a simple ans.:
Quote
The confusion here is:

Lets say A is not the same number over time:
Does "Randomize A" get compiled by visual basic by converting it into
"Rnd(-abs(A))" on each rnd call? or somthing close to that?

If you want Num give me a year by then I should learn Precal...

Freighting thoughts: Is collage going to exsept me if I dont know Precal??

---
I am reading , I am reading...
« Last Edit: February 25, 2005, 05:52:15 PM by Botsareus »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7709
    • View Profile
Rnd function
« Reply #5 on: February 25, 2005, 06:05:26 PM »
Sorry, I keep forgetting not everyone is a computer science and mathematics major :(

To answer your question, if VB works like C (and I have a hunch it does) this is how Randomize works:

Random numbers are generated from a function.  The next random number is generated from the one before it.  The next number should be statistically independant from the current number.

Here's a really bad but simple random function.  Let's pretend this is how VB does it:

Code: [Select]
Function rand (seed as integer) as integer
rand = seed * 3 + 1

End Function

Now, all random number generators have to be 'seeded'.  Since each value is made from the one before it, what do we do for the first value we want to generate?  We give it a 'seed value'.

Lets say we seed our generator with "1"

So we do this:

Code: [Select]
dim seed as integer
seed = 1

while true
  seed = rand(seed)
  print.debug(seed)
Wend

This shows us generating a list of 'random' numbers (I told you our function was bad but simple).

This will generate the same list of 'random' numbers everytime we run the program.   This is where psuedorandom space games like noctis and elite get their complexity.  They only have to store a single initial seed value and they can generate a list of random numbers to build their universe from.  It's the same for every time its run.

That's great, but what if we don't want the same list of random numbers everytime we run the program?  Well, since seed and rand(seed) are supposed to be statistically independant, as long as we can come up with a new seed everytime we run the program we can make a new, completely different random list.

What changes everytime the program is run?  That's right, the timer!  That blasted little bugger's been running down since sometime in the 1970s.  Always increasing, counting on and on, never tiring.

So we convert that timer value into whatever data format we're using, in my example an integer, and we use that as the seed each time the program's run.

That's what's happening when you type Randomize Timer.



Colleges will accept people that don't even know algebra.  Just means you get to pay them more money :rolleyes:
« Last Edit: February 25, 2005, 06:10:34 PM by Numsgil »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Rnd function
« Reply #6 on: February 25, 2005, 06:18:47 PM »
Thanks Num. The next random number is generated from the one before it. Time to go write a new function for smexe.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7709
    • View Profile
Rnd function
« Reply #7 on: February 25, 2005, 06:32:41 PM »
If you're making a new random number function (its kind of fun in a way) and you'd like to test if your new random number function is actually producing random numbers, you can try a simple stats correlation test.  You can do it in a Texas Instruments Ti83 plus (standard graphing calculator) by inputting all the numbers you get into a list and doing different regressions on it.  You should see a r^2 value of close to 0.  The closer to zero it is, the more random it is.

If you don't have a graphinc calculator, maybe you can find a similar program on the internet.  Or you can make your own!  Look up the algorithms for regression curves on any simple stats page on the internet.

Try exponential, linear, quadratic, logarithmic, and any others you can think of.
« Last Edit: February 25, 2005, 06:33:58 PM by Numsgil »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Rnd function
« Reply #8 on: February 25, 2005, 06:39:37 PM »
ok  :ph43r: <--- thats supposed to be a ninja right?
« Last Edit: February 25, 2005, 06:46:05 PM by Botsareus »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7709
    • View Profile
Rnd function
« Reply #9 on: February 25, 2005, 06:54:15 PM »
I'm not sure what emotion it's supposed to convey but it sure does look cool.   :ph43r:

Offline MightyPenguin

  • Moderator
  • Bot Destroyer
  • *****
  • Posts: 189
    • View Profile
Rnd function
« Reply #10 on: February 26, 2005, 12:22:43 PM »
How long does it take for VB's random function to repeat itself? I.e. how many values can it take?
« Last Edit: February 26, 2005, 03:16:02 PM by MightyPenguin »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Rnd function
« Reply #11 on: February 26, 2005, 02:13:21 PM »
I think I know but Mighty should reply to "The English" first

 :bigginangel: Bau :bigginangel:
 :evil: Bau :evil:

Offline MightyPenguin

  • Moderator
  • Bot Destroyer
  • *****
  • Posts: 189
    • View Profile
Rnd function
« Reply #12 on: February 26, 2005, 03:17:43 PM »
That topic had gone off topic by the third post. I'm really not sure if I have anything to add.

I only want to know if it's more than 2^64 values...

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Rnd function
« Reply #13 on: February 26, 2005, 03:54:28 PM »
Yes there are more,  Maybe 2 ^ 150 is close. But I dont have a computer science major so I dont know for sure.
« Last Edit: February 26, 2005, 03:55:02 PM by Botsareus »

Offline MightyPenguin

  • Moderator
  • Bot Destroyer
  • *****
  • Posts: 189
    • View Profile
Rnd function
« Reply #14 on: February 26, 2005, 04:02:36 PM »
Assuming you have the computer generate a new number every second, it should take 4.5382061861071679164704351389191e+37 years for the function to repeat itself. Note that the universe is only 1.37e+9 years old. Why on earth do you feel the need to make it more random?  :huh:

Oh well, each to their own, I suppose...

Numsgil, how many instructions would a P4 have to perform when you call the random function?
« Last Edit: February 26, 2005, 04:03:28 PM by MightyPenguin »