sydney.lambda
2019-7-28 17:51:27

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:


samdphillips
2019-7-28 17:56:25

something like: (let ([range (- end start)]) (+ start (* random range)))


samdphillips
2019-7-28 17:57:21

you’ll probably need to throw in a floor if you want integers


sydney.lambda
2019-7-28 17:58:29

Ahh, that makes sense. My lack of math skills can be a real source of frustration sometimes! Thank you :slightly_smiling_face:


krismicinski
2019-7-28 19:33:11

Not so much math skills as random factoids about how computers approximate math skills :wink:


krismicinski
2019-7-28 19:33:15

so don’t feel bad.


soegaard2
2019-7-28 19:36:58