Author Topic: Random Numbers?  (Read 4159 times)

Offline PhyrePhoX

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 2254
  • make RAW not WAR
    • PhyreWorX
Re: Random Numbers?
« Reply #15 on: 29 / April / 2008, 19:03:20 »
what do you mean by granularity? it's quite a big number, constantly changing. should be useful.


ab did you have any success? in your blog entry i read
Quote
You can see a patern develope in the randomness in the way the shots pulse. The script needs more work.
is it so? so waldos script didnt do the trick? maybe logging the output to a file will show us how random it is (or nor)?

Offline ab

  • Rookie
  • *
  • Posts: 17
Re: Random Numbers?
« Reply #16 on: 29 / April / 2008, 21:26:25 »
I couldn't get the code to work for parameterizing the size of the random number.

Waldos script works for me, but it would be cool to be able to constrain the random numbers to different limits each time I run the script. 

Could you check to see if you can parameterize random numbers?

Offline fbonomi

  • Sr. Member
  • ****
  • Posts: 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Random Numbers?
« Reply #17 on: 30 / April / 2008, 00:45:10 »
what do you mean by granularity?

Sorry, I meant resolution. I have never tried it and I was wondering if it was in in seconds, milliseconds or else

Offline fbonomi

  • Sr. Member
  • ****
  • Posts: 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Random Numbers?
« Reply #18 on: 30 / April / 2008, 00:55:06 »
you don't say what problem you have in the script... it makes it harder to solve it.

If the problem is non-randomness, then I must say that this bit of code:

Code: [Select]
random z
a=z%b

can introduce some non-randomness, especially evident if b is rather large..

for example, let's say b=200.

for values of z going from 0 to 199, a=z (in the range 0-199)
for values of z going from 200 to 255, a=z-200 (in the range 0-55)

so, assuming z is uniformly distributed, a will have a very non-uniform distribution: values of a in the range 0-55 will be double as frequent as larger values.

your method works well for values of b that are powers of two (128,64, 32...) or that are much smaller than 255, so this "folding" effect is less strong..

Is this your problem?

Offline PhyrePhoX

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 2254
  • make RAW not WAR
    • PhyreWorX
Re: Random Numbers?
« Reply #19 on: 30 / April / 2008, 04:43:56 »
what do you mean by granularity?

Sorry, I meant resolution. I have never tried it and I was wondering if it was in in seconds, milliseconds or else

it's ms.

okay, i created the following script that is compatible with my build that does what you want, ab. at least i hope so. i guessed by parametrization of the random numbers you meant the range, eh?
Code: FreeBasic
  1. @param h rand_min
  2. @default h 5
  3. @param i rand_max
  4. @default i 7
  5. random x
  6. a = h + x%(i-h+1)
  7. print "between "h "and "i ": "a
this generates numbers between (and including) 5 and 7.
i wrote a second script that can be used to "benchmark" the random number generator:
Code: FreeBasic
  1. @param y iterations
  2. @default y 1000
  3. @param h rand_min
  4. @default h 5
  5. @param i rand_max
  6. @default i 7
  7. print_screen 1
  8. k=get_tick_count
  9. print "rand_max: "i
  10. print "rand_min: "h
  11.  
  12. for z=0 to y
  13.         random x
  14.         a = h + x%(i-h+1)
  15.         print a
  16. next z
  17. l=get_tick_count
  18. print "Duration: ",(l-k)/1000," Seconds"
  19. print "the end."
  20. print_screen 0
  21. wait_click
  22. end
  23.  
you can specify the loop count and the range the random numbers should be in.
attached is a sample file with 10.000 iterations and random numbers ranging from 0 to 100 (i should have taken 0 to 10 i guess, but i wont do it again this night, took me 20 minutes :D
can be made faster though, for example by writing multiple random numbers per line, as writing to the sdcard (imo!) is the limiting factor here.
maybe one of you can check my attached file for randomness.
edit: i guess my generated numbers arent so random at all. i guess it is having to do with the 10 ms script delay and thus the same variations in tickcount. so a better and faster check would really be to either throw in some random sleeps or multiple randoms per line.
« Last Edit: 30 / April / 2008, 04:59:38 by PhyrePhoX »

Offline PhyrePhoX

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 2254
  • make RAW not WAR
    • PhyreWorX
Re: Random Numbers?
« Reply #20 on: 30 / April / 2008, 15:22:43 »
okay, next try:

edited my code, now it uses luminance, battery voltage & tickcount as seed.
Code: C
  1.  static void random_statement()
  2.  {
  3.      int var;
  4.      accept(TOKENIZER_RANDOM);
  5.      var = tokenizer_variable_num();
  6.      accept(TOKENIZER_VARIABLE);
  7.      srand((int)shooting_get_bv96()+(unsigned short)stat_get_vbatt()+get_tick_count());
  8.      ubasic_camera_sleep(rand()%10);
  9.      ubasic_set_variable(var, rand());
this happens when you call random from ubasic. as i am no fulltime coder i dont really know if this makes sense in a "random" way of sense. but i know that the outcome is much better than my last try.

Offline PhyrePhoX

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 2254
  • make RAW not WAR
    • PhyreWorX
Re: Random Numbers?
« Reply #21 on: 08 / May / 2008, 12:45:59 »
hey ab, i read in your blog that you finished the script. also you wrote a new script (time bandit) which sounds very interesting. care to share that in the "completed scripts" section of the forum, together with the random script? i guess the random script does use the build provided by me or jucifer, right?

Offline ab

  • Rookie
  • *
  • Posts: 17
Re: Random Numbers?
« Reply #22 on: 20 / May / 2008, 05:41:00 »
PhyrePhox - sorry for the long delay.  I need to remember to click the "email me when someone responds" button.

I will upload them both to the completed scripts section of the forum.  The random numbers inside the focus wobble rely on your build ... will that be a problem?

Thanks for checking out my blog.  I owe a great deal to all the work people here have done.  I've been shooting single frame animation movies for years ... and now my Canon A640 is my favorite camera for that application.

I have quite a few test films on my site too ... if anyone is interested in how these scripts come together.

Offline PhyrePhoX

  • Global Moderator
  • Guru Member
  • *****
  • Posts: 2254
  • make RAW not WAR
    • PhyreWorX
Re: Random Numbers?
« Reply #23 on: 20 / May / 2008, 18:07:19 »
those videos of yours - amazing. living proof that you dont need expensive equipment to produce high quality movies/pictures. the random command will *probably* be included in the official build soon, so i guess it isnt a problem (also, you mentioned in the script's thread that it needs my build, so no "customers" can complain :D).
let us know when your combat movie is finished :)
« Last Edit: 20 / May / 2008, 18:09:09 by PhyrePhoX »

CHDK Forum

Re: Random Numbers?
« Reply #23 on: 20 / May / 2008, 18:07:19 »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal