Search
Thursday, 28th of February 2019, 10:03:24 UTC
12:19:08
Lord_of_Life_
** NICK Lord_of_Life
14:39:12
mason
with a slash in front of it
14:59:49
jackdaniel
interesting read about formally-specified user interfaces: https://www.hillelwayne.com/post/formally-specifying-uis/
16:23:20
beach
jackdaniel: Interesting link.
16:38:32
_death
using statecharts for this is an interesting idea.. some months ago I started on a code generator in lisp to generate C++ code from statecharts.. I modeled a small application I wrote with it, but in the end I had other things to do ;) so the project is on hold.. the verification stuff, I don't care for
16:43:07
_death
this was the link I saw back then https://statecharts.github.io/
16:51:26
jackdaniel
oh, I thought I've posted it on #clim (I wouldn't post it here because it is not really related to lisp as such)
20:22:37
macbug
i tried to ask a question in #clnoobs but no answe, is it ok if i post eustion here?
20:22:53
macbug
sorry for the misspellings
20:23:55
macbug
hi, i'm trying to code a function with generates a random number, this random number should be between two given numbers.
20:24:02
macbug
(defun calculate-random-number (start end)
20:24:07
macbug
(let ((random-number (+ start (RANDOM end))))))
20:25:11
Xach
macbug: if start and end are 10 and 20, what is the range? the range is what you want to give to random.
20:25:30
Xach
you are on the right track with the (+ start ...) bit.
20:26:00
shka_
think about borderline cases
20:26:22
macbug
i have tried to give end the value of 100 and start a value of 1. The problem is that it always returns 45 or 93.
20:26:59
Xach
macbug: how do you test it?
20:27:21
pjb
macbug: now newbies go to #clschool, because some people thought #clnoobs was demeaning to newbies.
20:27:37
macbug
i compile the function in emacs + slime and run the function in the REPL
20:27:45
pjb
(+ start (random (- end start)))
20:27:46
sjl
(it actually switched because no one had ops to prevent the recent wave of spam)
20:28:16
Xach
macbug: and it always returns 45 or 93?
20:28:35
pjb
macbug: in the same lisp image, the pseudo-random number generator will generate other values.
20:28:54
pjb
But if you reboot the lisp image each time, then you would need to re-seed the PRNG!
20:29:16
pjb
(setf *random-state* (make-random-state t))
20:29:51
sjl
what happens when you run (loop :repeat 20 :collect (calculate-random-number 1 100)) ?
20:29:56
macbug
pjb: i tried that to, added it to the top of the source, re-compiled but no.
20:31:49
macbug
sjl: it returns NIL 20 times.
20:32:53
pjb
macbug: that's normal, since calculate-random-number returns 1.
20:33:03
sjl_
that's what I would expect. You bind the random number to a variable, but the body of your LET is empty, so it just returns NIL.
20:33:29
sjl_
I don't see how it could be returning 45 or 93 or anything aside from NIL as it's currently written
20:33:43
pjb
(defun random-between (start end) (+ start (random (- end start)))) (loop repeat 10 collect (random-between 50 100)) #| --> (82 74 94 81 87 79 75 90 50 56) |#
20:33:49
Xach
sometimes when i have a problem like that it is because i have renamed something but forgotten to use the new name.
20:34:00
Xach
but the old name lives on in the system, a ghostly prankster
20:34:02
sjl_
^^^ that is good advice to remember
20:36:49
macbug
i rewrote the function to:
20:36:51
macbug
(defun calculate-random-number (start end)
20:36:52
macbug
(+ start (random (- end start))))
20:37:04
macbug
as pjb wrote and it works
20:37:09
pjb
random-between is a better name than calculate-random-number.
20:37:15
pjb
1- all function calculate something.
20:37:24
pjb
2- it's not a generic random-number.
20:37:31
pjb
it's a random between start and end.
20:37:37
pjb
(random-between start end).
20:37:57
sjl_
inclusive of start, exclusive of end
20:38:31
pjb
Like all start end bounding index designators.
20:39:10
pjb
well, bounding index, since we don't have a sequence here to give an implicit end.
20:39:32
pjb
http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_b.htm
20:40:44
macbug
it will take me a while to understand this new funtion but atleast i can continue to work on my game, thx. I'll ask questions in #clschool from now.
20:41:27
vms14
https://trac.common-lisp.net/cl-weblocks/wiki/UserManual
20:47:09
pjb
macbug: there's nothing strange to understand here, but that when you add S to a number between A and B, you get an number between S+A and S+B.
20:47:52
pjb
macbug: so if you want start=S+A and end=S+B with and A=0, then start=S and end-start=B.
20:48:13
pjb
(random B) generate a number between A=0 and B.
Thursday, 28th of February 2019, 22:03:24 UTC