Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert real to exact integer in Racket?

Tags:

scheme

racket

How do I convert a value of the form 20.2 into something that (random ...) accepts?

I've tried these:

;; x defined by some earlier maths and of form 20.2

(random (round x))
(random (floor x))

But both return:

random: contract violation
expected: (or/c (integer-in 1 4294967087) pseudo-random-generator?)
given: 20.0
like image 346
Eric Clack Avatar asked Feb 13 '16 14:02

Eric Clack


People also ask

What does quotient mean in racket?

quotient : (integer integer -> integer) Purpose: to divide the first integer (exact or inexact) into the second; try (quotient 3 4) and (quotient 4 3)

How do you negate a number in a racquet?

Also note that if your programming language doesn't support negative numeric literals, you can still get at negative numbers by subtracting from zero. Example: (- 0 12) gets us -12 . Professional Racket will support the shorthand: (- 12) to negate 12 as well.

How do you know if something is an integer in scheme?

What you need to do is test each element in the list to see if it satisfies a condition (being an integer, in this case). When you evaluate (integer? (car list)) on a list of integers, you're checking if the first element in the list is an integer, and that's fine.

Is number a racket?

The numbers game, also known as the numbers racket, the Italian lottery, Mafia lottery or the daily number, is a form of illegal gambling or illegal lottery played mostly in poor and working class neighborhoods in the United States, wherein a bettor attempts to pick three digits to match those that will be randomly ...


1 Answers

These also work, and according to the documentation they're just shorthands for your approach:

(random (exact-round x))
(random (exact-floor x))
like image 161
Óscar López Avatar answered Sep 30 '22 02:09

Óscar López