Apologies for this being non racket-specific, but it’s part of a Racket project so I hope that’s alright.
I want to produce a (pseudo)random number between two ranges for rpg (dragon warrior!) damage calculation: from:
(EnemyStrength - HeroDefense / 2) / 4,
to:
(EnemyStrength - HeroDefense / 2) / 2
but I’m struggling to work it into my rng method. I’m passing around a stream of random numbers between 0 and 1, grabbing the car to get a random number and then the generator just becomes the cdr of the stream. Can anyone help me work out how I can use a random number between 0 and 1 to produce a random number between two ranges like that? Normally of course you’d just use (random lower upper) but I’m passing around the rng as an exercise in keeping things functional, and I can’t think how to use it to get the desired effect.
Thanks :slightly_smiling_face:
something like: (let ([range (- end start)])
(+ start (* random range)))
you’ll probably need to throw in a floor
if you want integers
Ahh, that makes sense. My lack of math skills can be a real source of frustration sometimes! Thank you :slightly_smiling_face:
Not so much math skills as random factoids about how computers approximate math skills :wink:
so don’t feel bad.
@sydney.lambda You could always use random-integer
https://docs.racket-lang.org/math/base.html?q=random-#%28def._%28%28lib._math%2Fbase..rkt%29._random-integer%29%29