#128546 - 2004-10-28 03:08 AM
Kixtart Mini-putt challenge for tonight
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Ok you late-night putters, get your nine iron out. Tonights Kixtart ultra-mini-putt golf challenge is as follows ...
Code:
For $i = 0 to 100
? "Random number between -1000 and 1000 = " + <the challenge>
Next
Fill in <the challenge> marker there, with some real code, that will display a random number between -1000 and 1000. No IF statements or other condional statements allowed ... just a nice simple one-liner expression type thingy.
|
|
Top
|
|
|
|
#128547 - 2004-10-28 04:29 AM
Re: Kixtart Mini-putt challenge for tonight
|
Jack Lothian
MM club member
   
Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
|
|
|
Top
|
|
|
|
#128549 - 2004-10-28 04:52 AM
Re: Kixtart Mini-putt challenge for tonight
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Code:
For $i = 0 to 100 ? "Random number between -1000 and 1000 = " rnd(2000)-1000 Next
|
|
Top
|
|
|
|
#128551 - 2004-10-28 05:22 AM
Re: Kixtart Mini-putt challenge for tonight
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Wouldnt this also generate a random number between -1000 and 1000
Code:
For $i = 0 to 100 ? "Random number between -1000 and 1000 = " Rnd(9) Next
didnt see anything about where at in between -1000 and 1000 it had to be..
|
|
Top
|
|
|
|
#128553 - 2004-10-28 10:28 AM
Re: Kixtart Mini-putt challenge for tonight
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here's a starter:
Code:
BREAK ON
For $i = 0 to 100
"Random number between -1000 and 1000 = "+(((@TICKS+(@MSECS*2)) MOD 1001)*(1-2*(@TICKS MOD 2))+Execute("sleep (3.0+@TICKS MOD 11)/1000")) ?
Next
Because it is such a small set, this works surprisingly well.
The "Execute" is not strictly necessary, but it makes the code a single expression in keeping with the spirit of the challenge.
It's a bit of a cheat, but without a way of maintaining a seed I can't think how else it can be done.
Feel free to Golf it.
|
|
Top
|
|
|
|
#128557 - 2004-10-29 10:39 AM
Re: Kixtart Mini-putt challenge for tonight
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Cute Richard 
Does it really work as well as Rnd? I suspect they might be on par but no matter I do like your solution - it is original 
Dunno. Given that RND is not actually random this is probably just as good for this small set.
If the set was larger it wouldn't be very useful.
If you are interested in comparing the both, run for each for a couple of hundred thousand iterations and plot a histogram of the number of times that each value is returned. If the RNG is truly random then it should be a fairly flat line.
I suspect that in a tight loop like this there is a posibility of getting into a repeating sequence. In the real world where other stuff will be going on which will take a variable amount of time to complete it probably isn't an issue.
The obvious big differences are
- My code is much, much slower because of the need to intoduce the small sleeps to peturb the algorithm.
- As my code does not have a seed you cannot guarantee to repeat the sequence.
- There is chance that the significant bits of @TICKS and @MSECS will repeat causing a repeating sequence where the loop is very tight.
|
|
Top
|
|
|
|
#128563 - 2004-10-31 04:42 PM
Re: Kixtart Mini-putt challenge for tonight
|
Jack Lothian
MM club member
   
Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
|
Cybex,
Just because something is generated by deterministic process doesn't mean we can recreate it even if we perfectly understand the underlying processes. The current output of the hypothetical fractal processes may depend on the initial conditions in the past – possibly at the moment of creation of the universe & we can never know these initial conditions so we can never simulate the processes even if we know the equations. A rather nihilistic view point in my opinion but Mandelbrot in particular has championed this viewpoint.
Sealeopard,
These natural phenomena that you refer to, may not be random. From the paradigm that I am coming from, Einstein was right when he said that he did not believe God played with dice & there was something missing in the theory of quantum mechanics & once we found the missing element, randomness would vanish. The random & probabilistic quantum effects that we observe in our real world may actually be generated because we live in a universe with 15 dimensions with all but 4 of the dimensions collapsed. It is the projection of these higher dimensions on our 4 dimensions, which gives the illusion of randomness. The implication here is that these so-called random process may be found to have ‘structure’ by a yet to be developed statistical test. After all, this is the history of the development of random number generators. Each time we develop a new generator that overcomes a previous weakness, someone comes along and points that the new generator has an observable non-random structure. These tests for structure are becoming more & more esoteric each year. It is like peeling an onion with an infinite number of layers.
_________________________
Jack
|
|
Top
|
|
|
|
#128564 - 2004-11-01 10:22 AM
Re: Kixtart Mini-putt challenge for tonight
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Regarding the randomness of Richards’s code it is not truly random in the sense the outcome is re-creatable. It is not easily re-creatable but it is not impossible. Given all the environmental variables preset I.E. the uptime of the system, the current millisecond in time, and so on, and the output would be the same each and every time.
You're missing a bit of the story. This is true, but only if the action is not subsequently subject to external influnces.
In the case of your PC it will be peturbed by small things like minor fluctuations in power supply or heat, and large things like your anti-virus software, screen saver or fast-find kicking in.
In fact, my code is *more* random than the built-in, by accident of design rather than any intention 
The built-in uses a well tried and trusted method of starting with a seed number and on each iteration pushing it through an algorithm which appears to generate a random number.
The number is not of course random, it is entirely predictable. I could give you a seed number and then describe the next 10,000 numbers that will be returned every single time, without error.
You can't do that with my algorithm. If you managed to get @TICKS and @MSECS the same then the numbers at the start of the process would be identical. However, no two computers will function exactly the same, especially over an extended period. This means that without some sort of governer the results will diverge.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1172 anonymous users online.
|
|
|