It is currently Tue Jun 23, 2026 4:55 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 16 posts ] 
Author Message
 Post subject: Random numbers PAIN
PostPosted: Sun Sep 02, 2012 7:34 pm  (#1) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4826
Location: Bendigo Vic. Australia
GIMP Version: 2.6.11
Operating System: Windows
OS Version: XP - SP3
GIMP Experience: Beginner Level



Here I am stuck again, this time with random numbers, my equation is (set! gradient-shape (+ 6 (random 2))).

I hoped it would return either 6,7 or 8 but it returns 7 and occasionally 6 but never 8

Oh woe is me :cry

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Random numbers PAIN
PostPosted: Sun Sep 02, 2012 8:24 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4826
Location: Bendigo Vic. Australia
I'm scratching my head (no fleas) but this worked I think :yes :gimp

(set! gradient-type (+ 6 (random 3)))
(if (< gradient-type 6.8) (set! gradient-type 6))
(if (> gradient-type 7.2) (set! gradient-type 8))
(if (and (> gradient-type 6.8) (< gradient-type 7.2)) (set! gradient-type 7))

There must be something easier I'm sure, and there was thanks to Tux

Isn't gimp fun

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Last edited by Graechan on Sun Sep 02, 2012 9:36 pm, edited 1 time in total.

Top
 Post subject: Re: Random numbers PAIN
PostPosted: Sun Sep 02, 2012 9:11 pm  (#3) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5241
Location: Gimpville
Your example is: (+ 6 (random 2))

Should be (+ 6 (random 3)) ... works for me..

Image

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Sun Sep 02, 2012 9:22 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4826
Location: Bendigo Vic. Australia
Thank you Tux I did not know you could use the console to test equations,that is great :hi5

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Sun Sep 02, 2012 9:29 pm  (#5) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16042
Glad you figured it out. :)
I was wondering if random is actually a function in Schema or if random is your own variable?

_________________
Image


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Sun Sep 02, 2012 9:46 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4826
Location: Bendigo Vic. Australia
I think it's a function of scheme, I just noted it from reading other peoples scripts i.e. you never stop learning.

I'd love a list of these scheme functions

(random 3) returns 0,1 or 2 but never 3

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Sun Sep 02, 2012 10:09 pm  (#7) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5241
Location: Gimpville
Yes, the console is a great tool for testing. :bigthup

The random function is included in Script-fu. You can just use rand for short.

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 12:27 am  (#8) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16042
I would like a list of all the functions myself. :)
Those and also a list of all the deprecated PDB calls.

Thanks guys.

Isn't round also a function?

_________________
Image


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 1:19 am  (#9) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5241
Location: Gimpville
Yep..

(round (/ 39 7)) = 6.0

(floor (/ 39 7)) = 5.0

(trunc (/ 39 7)) = 5

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 1:53 am  (#10) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Graechan wrote:
I'd love a list of these scheme functions

(* *colon-hook* *error-hook* *features* *handlers* *pi* *seed* + - / < <= <> = => > >= abs acons acos and anyatom->string append apply aref aset asin assoc assq assv atan atom->string atom? begin boolean? butlast caaaar caaadr caaar caadar caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr cadr call-with-current-continuation call-with-input-file call-with-output-file call/cc car case catch cdaaar cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr ceiling char->integer char-alphabetic? char-ci-cmp? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-cmp? char-downcase char-lower-case? char-num char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port close-port closure? cmp complex? cond cond-eval cond-eval-and cond-eval-or cond-expand cond-expand-runtime condition cons cons-array cos current-environment current-input-port current-output-port define define-macro define-with-return defined? delay delq display do duplicate else environment? eof-object? eq? equal? eqv? error eval eval-polymorphic even? exact->inexact exact? exp expt floor fmod foldr fopen for-each force fread fread-get-chars gc gc-verbose gcd generic-assoc generic-member gensym get get-closure-code gettimeofday head if inexact->exact inexact? inport input-output-port? input-port? integer->char integer? interaction-environment lambda large last last-pair lcm len length let let* letrec list list* list->string list->vector list-cnt list-ref list-tail list? load log macro macro-expand macro? make-closure make-environment make-list make-string make-vector map mapcar max member memq memv modulo more-handlers? msrg-rand negative? newline nil not nreverse nth null? number->string number? oblist odd? open-input-file open-input-output-file open-input-output-string open-input-string open-output-file open-output-string or outport output-port? pair? peek-char pop-handler port? positive? pow pred prin1 print procedure? prog1 push-handler put quasiquote quit quote quotient rad rand random random-next ratio rational? re-match read read-char real? realtime remainder reverse round set! set-car! set-cdr! set-input-port set-output-port sin sqrt srand strbreakup strcat strcmp string string->anyatom string->atom string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-cmp? string-copy string-fill! string-length string-lessp string-ref string-set! string-trim string-trim-left string-trim-right string<=? string<? string=? string>=? string>? string? strlen substring substring-equal? succ symbol->string symbol-bound? symbol? tail tan the-environment throw time tracing trunc truncate unbreakupstr unless unquote unquote-splicing unzip1-with-cdr unzip1-with-cdr-iterative usleep vector vector->list vector-equal? vector-fill! vector-length vector-ref vector-set! vector? verbose when which while with-input-from-file with-input-output-from-to-files with-output-to-file write write-char zero?)

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 2:39 am  (#11) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Rod wrote:
... and also a list of all the deprecated PDB calls.

Run the following code in your Script-fu console:
(let ((all-procs (cadr (gimp-procedural-db-query ".*" ".*" ".*" ".*" ".*" ".*" ".*" ))))
  (map (lambda (proc-name)
    (let ((blurb (car (gimp-procedural-db-proc-info proc-name))))
      (when (and (>= (string-length blurb) 28)
                 (string=? (substring blurb 0 28) "This procedure is deprecated") )
        (display proc-name)
        (newline) )))
    all-procs )
  #t )


For example, for 2.6 the following list of deprecated procedures is generated:
gimp-image-free-shadow gimp-shear gimp-text-get-extents gimp-path-set-locked gimp-palettes-get-palette-entry gimp-palettes-get-palette gimp-flip gimp-path-get-points gimp-path-get-current gimp-path-get-tattoo gimp-gradients-sample-uniform gimp-gradients-get-gradient-data script-fu-copy-visible gimp-brushes-set-spacing gimp-levels-auto gimp-path-stroke-current gimp-drawable-set-image gimp-path-set-points gimp-text gimp-path-import gimp-path-set-tattoo gimp-brushes-get-brush gimp-image-add-layer-mask gimp-gradients-sample-custom gimp-path-to-selection gimp-path-delete gimp-perspective gimp-brushes-get-brush-data gimp-transform-2d gimp-path-get-point-at-dist gimp-path-set-current gimp-brushes-get-spacing gimp-patterns-get-pattern-data gimp-patterns-get-pattern gimp-path-get-locked gimp-path-list gimp-image-remove-layer-mask gimp-rotate gimp-scale gimp-get-path-by-tattoo gimp-palettes-set-palette gimp-palette-refresh gimp-image-floating-selection gimp-color-picker gimp-channel-get-name gimp-brushes-get-paint-mode gimp-layer-set-name gimp-undo-push-group-start gimp-gradients-get-active gimp-drawable-image gimp-drawable-bytes gimp-layer-set-preserve-trans gimp-channel-ops-duplicate gimp-brushes-list gimp-gradients-set-active gimp-brushes-set-brush gimp-convert-rgb gimp-gradients-get-gradient gimp-blend gimp-crop gimp-undo-push-group-end gimp-channel-set-name gimp-channel-ops-offset gimp-image-set-cmap gimp-palette-get-foreground gimp-bucket-fill gimp-patterns-set-pattern gimp-brushes-set-opacity gimp-palette-get-background gimp-brushes-set-paint-mode gimp-palette-set-default-colors gimp-selection-clear gimp-brushes-get-opacity gimp-channel-set-tattoo gimp-gradients-set-gradient gimp-image-get-cmap gimp-layer-get-preserve-trans gimp-palette-swap-colors gimp-convert-grayscale gimp-palette-set-background gimp-temp-PDB-name gimp-layer-get-name gimp-channel-get-tattoo gimp-layer-mask gimp-layer-set-tattoo gimp-image-active-drawable gimp-channel-delete gimp-layer-set-linked gimp-channel-set-visible gimp-patterns-list gimp-convert-indexed gimp-layer-delete gimp-layer-get-tattoo gimp-layer-set-visible gimp-layer-get-visible gimp-channel-get-visible gimp-layer-get-linked gimp-palette-set-foreground

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 2:43 am  (#12) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16042
Wow! Thanks Saul. :)

You are the man.

_________________
Image


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 2:51 am  (#13) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16042
I thought the function "when" wasn't allowed/used in script-fu?

_________________
Image


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 2:57 am  (#14) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
'when' is a macro.

(when <condition> <body>)

is equivalent to

(if <condition> (begin <body>))

where <body> is one or more statements.

Likewise,

(unless <condition> <body>)

is equivalent to

(if (not <condition>) (begin <body>))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 3:11 am  (#15) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
According to Scheme in One Defun the definitions of rand and random are:
(rand modulus)
Computes a random number from 0 to modulus-1. Uses C library rand.
(random modulus)
Computes a random number from 0 to modulus-1. Uses C library random.


b10h4z4rd has asked me to write some code to find all the scripts that are using deprecated functions and I'm planning on using a slightly different version of the search that relies on the gimp-procedural-db-query functionality:
(set! deprecated_function_list (cadr (gimp-procedural-db-query "" "deprecated" "" "" "" "" "")))


And I believe saulgoode's deprecated list is for 2.6 as 2.8 gives 188 deprecated functions (including 1 script: script-fu-copy-visible)

Kevin


Top
 Post subject: Re: Random numbers PAIN
PostPosted: Mon Sep 03, 2012 3:51 am  (#16) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16042
Yes Saul said it was for Gimp-2.6. :)
Thanks Kevin.

_________________
Image


Top
Post new topic Reply to topic  [ 16 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group