Pontoon / Blackjack / 21 Dealer for Inform

9 views
Skip to first unread message

Destriarch

unread,
Jun 6, 2005, 9:16:58 AM6/6/05
to
OK, the code is messy, but it works and I'm tres proud of this little
piece of work. It produces a dealer capable of playing Pontoon
(sometimes called Blackjack or 21) with the player by using simple
vocal commands. Just copy/paste the whole text below the room you want
the dealer to appear in and you'll be fine. Other tips appear in the
code.

!Blackjack Dealer by Ashok Desai;

!Declare the globals used by the code. Pack_of_cards holds a;
!shuffleable deck of 52 cards, currentcard represents the current;
!position in the deck, cardhand and cardace are used when the code;
!needs to calculate the best value of a pontoon hand.;

array pack_of_cards -->52;
Global currentcard = 0;
array cardhand --> 2;
array cardace --> 2;

!The next few routines are lifted or adapted from those written in;
!the user manual for Inform. Why change something that works?;

[ ExchangeTwo x y z;
! Randomly choose two different numbers between 0 and 51:
while (x==y) {
x = random(52) - 1; y = random(52) - 1;
}
z = pack_of_cards-->x; pack_of_cards-->x = pack_of_cards-->y;
pack_of_cards-->y = z;
];

[ PrintCard n;
switch(n%13) {
0: print "Ace";
1 to 9: print n%13 + 1;
10: print "Jack"; 11: print "Queen"; 12: print "King";
}
print " of ";
switch(n/13) {
0: print "Hearts"; 1: print "Clubs";
2: print "Diamonds"; 3: print "Spades";
}
];

!I deleted the part of this routine that writes the exact order of;
!all the cards in the deck, but it's otherwise identical.;

[ Reorder i;
! Create the pack in "factory order":
for (i=0:i<52:i++) pack_of_cards-->i = i;
! Exchange random pairs of cards for a while:
for (i=1:i<=100:i++) ExchangeTwo();
currentcard = 0;
];

!This routine simply grabs the next card in line, points the deck;
!to the next card along, and returns the appropriate value. In;
!other words, read this into an attribute when you want to take a;
!card off the deck;

[getcard x;
x = pack_of_cards --> currentcard;
currentcard = currentcard + 1;
return x;
];

!This routine is called when a player gets a new card. It ;
!increments the total for non-ace cards if the new card is not;
!an ace, and increments the number of aces if it is. It is
!necessary to keep these two values separate so that the code can;
!figure out how many aces to convert into 11's.;

[addcard x player;
!0 means add to the player's hand. 1 means add to the dealer's hand;
x = x%13+1;
if (x > 10) x = 10; !if it's a picture card, make it worth 10;
if (x == 1) cardace-->player = cardace-->player + 1;
else cardhand-->player = cardhand-->player + x;
];

!This beauty calculates the exact value of each hand. Basically,;
!it takes the total value of all non-ace cards, then goes through;
!all the aces checking to see if having this one at 11 would cause;
!the player to go bust, if all the others were valued at 1.;

[pontoonvalue player x f;
x = cardhand-->player;
for (f=1:f<=cardace-->player:f++)
if (x + 11 + cardace-->player - f <= 21) x = x + 11; else x = x + 1;
return x;
];

!This routine ends the game, tidies things up, and rewards the;
!player if a reward is on offer.;

[endgame winner dealer;

if (winner == 0) {print (The) dealer; print " grudgingly hands over
your winnings.^";}
!If you want to include a prize, then put the code for it here;
!inside the {curly brackets};
else {print "~Sorry friend,~ "; print (the) dealer; print " says
cheerfully, ~You lose!~^";}
dealer.gameon = 0;
return;];

!And now the dealer himself.;

Object -> gambler "gambler"
with name "gambler",
gameon 0, stick 0,
description "A man with a deck of cards. (Type <ask gambler about
rules> and maybe he will tell you how to play!)",

!The game's commands must all be spoken to the dealer.;

life[c1 c2 f;answer: switch (noun) {

!The deal command initialises a new game, if none is in progress;
!If you want to include a cost for the game, sandwich this code in;
!your own 'if' statement's curly brackets;

'deal' : if (self.gameon == 0) {

!First, we initialise the necessary values and tell the dealer;
!that the game is on;

reorder(); self.gameon = 1; self.stick = 0;
for (f=0:f<2:f++) {cardhand-->f = 0; cardace-->f = 0;}

!Next, we deal two cards each to both players, and tell them what they
are and their totals;

c1 = getcard(); c2 = getcard(); addcard(c1,0);
addcard(c2,0); print "The gambler deals you the ";
printcard (c1); print " and the "; printcard (c2);
print ", for a running total of "; print pontoonvalue(0);
print ".";

c1 = getcard(); c2 = getcard(); addcard(c1,1); addcard
(c2,1); print "^To himself, he deals the "; printcard (c1);
print " and the "; printcard (c2); print ", for a running
total of "; print pontoonvalue(1); print ".^";

!Finally we check to see if either player has Pontoon;

if (pontoonvalue(1) == 21) {print "^~Pontoon!~ shouts the
dealer triumphantly, ~I win!~^"; endgame(1,self);}
else if (pontoonvalue(0) ==21) {print "^You smugly show
the gambler your Pontoon hand.^"; endgame(0,self);}
return;
}
else print_ret "You're halfway through a game, you might
as well finish it.";

!Now we need to tell the dealer what happens if a player accepts;
!a new card, and how it should react.;

'twist' : if (self.gameon == 1) {c1 = getcard(); addcard
(c1,0);

!Deal to the player, make sure you're not bust;
print "The gambler deals you the "; printcard (c1);
print ".";if (pontoonvalue(0) > 21) {print " You have gone
bust!^"; endgame(1,self);} else {print " Your current
total is "; print pontoonvalue(0); print ".^";

!Check to see if the dealer wants a card, and if he goes bust.;
if ((pontoonvalue(1) <= 17 || pontoonvalue(1) <
pontoonvalue(0)) && self.stick ~= 1) {c1 = getcard();
addcard(c1,1); print "The dealer draws the "; printcard
(c1); if (pontoonvalue(1) > 21) {print " and goes bust!^";
endgame(0,self); return;} else {print " for a running
total of "; print pontoonvalue(1); print ".";}}
else if (self.stick == 0) {self.stick = 1; print "The
gambler sticks at "; print pontoonvalue(1); print ".^";}
else {print "You need to beat "; print pontoonvalue(1);
print ".^";}}

!And round off the action, or complain if no game is in progress;

return;} else print_ret "There is no game in progress - <say deal>
first.";

!Last part now! This is what happens when the player sticks.;

'stick', 'stay' : if (self.gameon == 1) {
print "You stick at "; print pontoonvalue(0); print ".^";

!We tell the player what value they have stuck upon. Now the;
!dealer will continue drawing cards until he either goes bust;
!or beats the player's total. Note that if he already stuck, he;
!won't be able to do this as the while loop will never trigger.;

while (pontoonvalue(1) < pontoonvalue(0) &&
self.stick ~= 1) {c1 = getcard(); addcard(c1,1);
print "The dealer draws the "; printcard(c1);
if (pontoonvalue(1) > 21) {print " and goes bust!^";
endgame(0,self); return;} else {print " for a running
total of "; print pontoonvalue(1); print ".^";}}

print "The gambler sticks at "; print pontoonvalue(1);
print ".^";

!This part is technically not necessary, but better safe than;
!sorry. It checks to see which player has won. To be honest, if;
!it gets to this point in the code then mathematically the dealer;
!should already have won, but I put it like this so that people;
!could more easily fiddle with the code.;

if (pontoonvalue(0) > pontoonvalue (1)) endgame(0,self);
else endgame(1,self); return;} else print_ret "There is no
game in progress - <say deal> first.";

!You can continue the answer case statement here if you want to;
!make the dealer respond to other words too.;

};print_ret "The gambler doesn't seem to care for that.";

!And, as promised in the description earlier, here the rules of;
!the game are briefly explained.;

ask : switch (second) {
'rules', 'game', 'pontoon', 'cards', 'play' : print_ret "The gambler
smiles, ~This is a very simple game friend, you'll get the hang of it
in no time. Just <say deal> and I'll deal
you two cards, and another two for myself. The idea is to get as close
to 21 without going over. Face cards like the king, queen and jack are
all worth 10 points. The Ace is worth either one or eleven, depending
on which would be better for you. Provided you haven't 'gone bust' you
can ask me for another card - just <say twist> - and I can do the same.
If you're happy with your score you can <say stick> instead. Whoever
gets closer to 21 wins the hand, if we draw then I win the hand. Oh and
to show it's all above board and no cheating is going on, I'll shuffle
the cards at the beginning of each hand.~";
};print_ret "The gambler doesn't seem to care for that.";],
has animate static;

samwyse

unread,
Jun 8, 2005, 4:25:16 AM6/8/05
to
Destriarch wrote:
> OK, the code is messy, but it works and I'm tres proud of this little
> piece of work.

Overall, it looks great. I have one nit, and a couple of comments. If
you can wrap this into an 'include' file, you should submit it to the
archive.

> !The next few routines are lifted or adapted from those written in;
> !the user manual for Inform. Why change something that works?;

Except that it doesn't, quite...

> [ Reorder i;
> ! Create the pack in "factory order":
> for (i=0:i<52:i++) pack_of_cards-->i = i;
> ! Exchange random pairs of cards for a while:
> for (i=1:i<=100:i++) ExchangeTwo();
> currentcard = 0;
> ];

From a little later in DM4: "A hundred exchanges is only just enough.
Redefining SHUFFLES as 10,000 takes a lot longer, while redefining it as
10 makes for a highly suspect result. Here is a more efficient method of
shuffling (contributed by Dylan Thurston), perfectly random in just 51
exchanges."

pack_of_cards-->0 = 0;
for (i=1:i<52:i++) {
j = random(i+1) - 1;
pack_of_cards-->i = pack_of_cards-->j; pack_of_cards-->j = i;
}

> if (winner == 0) {print (The) dealer; print " grudgingly hands over
> your winnings.^";}

I notice that all of your print statements are coded like this one. Do
you realize that you can save a bit of typing by doing this:

if (winner == 0) {print (The) dealer, " grudgingly hands over your
winnings.^";}

> Provided you haven't 'gone bust' you


> can ask me for another card - just <say twist> - and I can do the same.
> If you're happy with your score you can <say stick> instead.

FYI, when playing Blackjack in Las Vegas, you generally say "hit me" and
"stand".

Graham Holden

unread,
Jun 8, 2005, 5:07:52 AM6/8/05
to
On Wed, 08 Jun 2005 08:25:16 GMT, samwyse <deja...@email.com> wrote:

>
>FYI, when playing Blackjack in Las Vegas, you generally say "hit me" and

Violence isn't the answer to this one.

>"stand".
You're already standing up.

;-)

Regards,
Graham Holden (g-holden AT dircon DOT co DOT uk)
--
There are 10 types of people in the world;
those that understand binary and those that don't.

Destriarch

unread,
Jun 8, 2005, 5:47:06 AM6/8/05
to
I will probably include the extra verbs for 'hit' and 'stand', but the
game isn't set in Las Vegas, it's set in a twisted version of Victorian
England. In that setting, you would use 'Twist' and 'Stick' which are
the English versions. This is also why it's called Pontoon in the game,
not Blackjack - English blackjack is a completely different game. Feel
free to change the commands if you use the dealer yourself to whatever
you feel comfortable with, it's all open to interpretation by the
individual.

And thanks for the shuffling tip, I must have missed the updated
version, I'll swap it over

Ash

Destriarch

unread,
Jun 8, 2005, 8:01:55 AM6/8/05
to
I tidied up a few loose ends, included the extra commands for Vegas
style (although the rules description you will have to change by hand -
not too difficult) and included a new feature. Now, when you include
the file, there are three routines that can be altered using the
replace command.

blackjack_win -- this routine is triggered when the player wins,
funnily enough. Good for providing cash or object prizes. The default
routine just prints a standard winning message.

blackjack_lose -- same sort of thing for when the player loses. You can
use it to supply a custom losing message, or make other things happen
when the player loses a game. The default routine just prints a
standard losing message.

blackjack_cost -- a checking routine that tests to see if the game can
take place. Insert your own conditions into this routine and make it
return either true or false based on those conditions, along with
printing off any error messages you may want the player to see, i.e.
"You don't have enough money for the stake!" is what I am using in my
game. If a game is already in progess, then the 'finish this game
first' message takes precedence. The default routine simply returns
true without any adornments, making it a free-to-play game.

You can also now alter the dealer's stickat attribute (i.e.
dealer.stickat = 15) to make the dealer stick when he reaches a
particular score, provided you're not beating him at the time. The
default is 17.

I'm off to try and find out how to submit it to this mysterious archive
of which you speak...

Destriarch

unread,
Jun 8, 2005, 8:12:59 AM6/8/05
to
Forgot to mention... if you want players to pay for their games
somehow, then be sure to remove the payment or related object bribe or
whatever during the 'can the player pay?' routine. If you remove it
only when the player loses, then it would be possible for the player to
escape from the area, get rid of whatever it was, return, finish the
game, then go back and retrive the goods without losing them during the
'lose' portion. Of course this depends heavily on how you code those
routines, but better safe than sorry, grab the payment as soon as you
know the player has it and wants to play!

Ross Presser

unread,
Jun 8, 2005, 11:17:21 AM6/8/05
to
On Wed, 08 Jun 2005 08:25:16 GMT, samwyse wrote:

> Here is a more efficient method of
> shuffling (contributed by Dylan Thurston), perfectly random in just 51
> exchanges."
>
> pack_of_cards-->0 = 0;
> for (i=1:i<52:i++) {
> j = random(i+1) - 1;
> pack_of_cards-->i = pack_of_cards-->j; pack_of_cards-->j = i;
> }

This is the agreed-upon best random deal function, yes. It was popularized
by Knuth, among others, and the earliest reference I can find for the
shuffling algorithm on which it is based is 1938. As long as random() can
be trusted to completely uniformly-distributed, unbiased random numbers, it
is the best possible deal algorithm -- it has an equal probability of
returning any of the 52! deals.

However, I don't know how good Inform's random() is.

Destriarch

unread,
Jun 8, 2005, 1:17:14 PM6/8/05
to
No better or worse than any random() feature I fear. There is no way
that a computer can reliably generate truly random numbers, it merely
has to make do with measures such as checking the current clock time
and running it through a progressive algorithm. It's good enough for
most purposes though, that's the main thing.

Andrew Plotkin

unread,
Jun 8, 2005, 1:59:21 PM6/8/05
to

I'm not sure what you're replying to here. Most IF interpreters go
straight to the system-level random number generator, which is (as you
say) good enough on modern machines.

--Z

"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
I'm still thinking about what to put in this space.

Ross Presser

unread,
Jun 8, 2005, 4:14:36 PM6/8/05
to
On Wed, 8 Jun 2005 17:59:21 +0000 (UTC), Andrew Plotkin wrote:

> Here, Destriarch <Eldritc...@aol.com> wrote:
>> No better or worse than any random() feature I fear. There is no way
>> that a computer can reliably generate truly random numbers, it merely
>> has to make do with measures such as checking the current clock time
>> and running it through a progressive algorithm. It's good enough for
>> most purposes though, that's the main thing.
>
> I'm not sure what you're replying to here. Most IF interpreters go
> straight to the system-level random number generator, which is (as you
> say) good enough on modern machines.

He was replying to the last line of my comment:

> However, I don't know how good Inform's random() is.

What do you mean by "system-level random number generator"? /dev/random on
a unix machine might make sense, but Windows doesn't provide any such thing
as far as I know -- and I'm positive that DOS didn't.

Do you mean an interpreter-provided RNG? That then would only be as good as
the person who wrote the interpreter....

A very small amount of bias in the RNG can manifest itself as a perceptible
difference in the deck deal probabilities. Something that could be
exploited by a really fanatical blackjack player. :)

All right, I'm being ridiculous. The risk of such a fanatic is very small,
and even if he does, what's he achieved? He beat an Inform game unfairly.
Big deal....

Andrew Plotkin

unread,
Jun 8, 2005, 9:06:22 PM6/8/05
to
Here, Ross Presser <rpre...@nospamgmail.com.invalid> wrote:
> On Wed, 8 Jun 2005 17:59:21 +0000 (UTC), Andrew Plotkin wrote:
>
> > Here, Destriarch <Eldritc...@aol.com> wrote:
> >> No better or worse than any random() feature I fear. There is no way
> >> that a computer can reliably generate truly random numbers, it merely
> >> has to make do with measures such as checking the current clock time
> >> and running it through a progressive algorithm. It's good enough for
> >> most purposes though, that's the main thing.
> >
> > I'm not sure what you're replying to here. Most IF interpreters go
> > straight to the system-level random number generator, which is (as you
> > say) good enough on modern machines.
>
> He was replying to the last line of my comment:
>
> > However, I don't know how good Inform's random() is.
>
> What do you mean by "system-level random number generator"?

The one in libc.

David Fisher

unread,
Jun 8, 2005, 10:05:16 PM6/8/05
to

"samwyse" <deja...@email.com> wrote in message
news:MXxpe.1912$751....@newssvr30.news.prodigy.com...

>
> From a little later in DM4: "A hundred exchanges is only just enough.
> Redefining SHUFFLES as 10,000 takes a lot longer, while redefining it as
> 10 makes for a highly suspect result. Here is a more efficient method of
> shuffling (contributed by Dylan Thurston), perfectly random in just 51
> exchanges."
>
> pack_of_cards-->0 = 0;
> for (i=1:i<52:i++) {
> j = random(i+1) - 1;
> pack_of_cards-->i = pack_of_cards-->j; pack_of_cards-->j = i;
> }

Minor fix to make sure (pack_of_cards-->i) and (pack_of_cards-->j) are
swapped correctly:

pack_of_cards-->0 = 0;
for (i=1:i<52:i++) {
j = random(i+1) - 1;

temp = pack_of_cards-->i ;


pack_of_cards-->i = pack_of_cards-->j;

pack_of_cards-->j = temp;
}

David Fisher


Destriarch

unread,
Jun 9, 2005, 4:02:30 AM6/9/05
to
To be honest he's not that hard to beat anyway ;) otherwise there
wouldn't be any point since in my game you have to beat him quite a few
times before you have enough money for the things you need to buy. But
he plays intelligently enough for now. Still not found this archive to
submit the code to though...

Ash

Rikard Peterson

unread,
Jun 9, 2005, 4:44:37 AM6/9/05
to

Destriarch wrote in
news:1118303695.9...@o13g2000cwo.googlegroups.com:

> Still not found this archive to submit the code to though...

http://www.ifarchive.org/

Shadow Wolf

unread,
Jun 9, 2005, 12:11:53 PM6/9/05
to
"David Fisher" <da...@hsa.com.au> wrote in
news:TyNpe.19018$Le2.1...@nasal.pacific.net.au:

Your algorithm fails to initialize the array, hence all locations but one
would be uninitialized (either garbage or 0). The algorithm provided by
Samwyse both initializes and shuffles in one pass.

--
Shadow Wolf
shadowolf3400 at yahoo dot com
Stories at http://www.asstr.org/~Shadow_Wolf
AIF at http://www.geocities.com/shadowolf3400

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Richard Bos

unread,
Jun 9, 2005, 1:09:32 PM6/9/05
to
Andrew Plotkin <erky...@eblong.com> wrote:

> Here, Ross Presser <rpre...@nospamgmail.com.invalid> wrote:
> > On Wed, 8 Jun 2005 17:59:21 +0000 (UTC), Andrew Plotkin wrote:
> >
> > > I'm not sure what you're replying to here. Most IF interpreters go
> > > straight to the system-level random number generator, which is (as you
> > > say) good enough on modern machines.

> > What do you mean by "system-level random number generator"?
>
> The one in libc.

Which libc? The one on MacOS 9? The one on MS Windows? On a Revo?

Richard

Richard Bos

unread,
Jun 9, 2005, 1:09:30 PM6/9/05
to
Ross Presser <rpre...@NOSPAMgmail.com.invalid> wrote:

> As long as random() can
> be trusted to completely uniformly-distributed, unbiased random numbers, it
> is the best possible deal algorithm -- it has an equal probability of
> returning any of the 52! deals.
>
> However, I don't know how good Inform's random() is.

Inform does not have its own random() - or rather, Inform's random()
should (AFAIK does) use the ZMachine's random opcode. How good this
opcode is depends on the implementation of the 'terp. The natural thing
for a 'terp written in C would be to use C's rand() function, and that,
too, varies widely in quality per compiler.
Some 16-bit C compilers for MS-DOS used the example code in the C
Standard, which is notoriously bad for technical reasons[1]; IIRC with
the result that some Infocom games could not be won on these 'terps.

Richard

[1] Basically, it is a minimal rand() implementation which would be
conforming for every possible ISO C implementation and is simple to
understand, but the resulting restrictions - e.g., a RAND_MAX of 32767 -
make it a very poor RNG.

Ross Presser

unread,
Jun 9, 2005, 4:07:08 PM6/9/05
to

I believe he meant what I originally thought, that inform's random()
request is supplied by the interpreter, and whoever wrote the interpreter
most likely relied on libc. So it would depend on the interpreter, and the
language being compiled, and the platform it's running on. Windows has no
libc; gcc and MSVC6 and other C compilers all have their own libc for
Windows. Under cygwin or linux, libc is a shared library / DLL (glibc). And
so on.

An overachieving interpereter writer could use a cryptographically strong
RNG instead of libc's random() if they wanted.

Ross Presser

unread,
Jun 9, 2005, 4:22:31 PM6/9/05
to
On 9 Jun 2005 11:11:53 -0500, Shadow Wolf wrote:

> [David Fisher's] algorithm fails to initialize the array, hence all locations but one

> would be uninitialized (either garbage or 0). The algorithm provided by
> Samwyse both initializes and shuffles in one pass.

Yup. Conceptually, it creates a card out of thin air, picks a random card
R from what's already in the deck being stacked, replaces that random card
with the new card, and puts the random card R on the top of the deck.

David Fisher

unread,
Jun 9, 2005, 10:46:07 PM6/9/05
to
"Shadow Wolf" <shadow...@NOSPAMyahoo.invalid> wrote in message
news:Xns96705D6B88523...@38.119.71.105...

> "David Fisher" <da...@hsa.com.au> wrote in
> news:TyNpe.19018$Le2.1...@nasal.pacific.net.au:
>>>
>>> pack_of_cards-->0 = 0;
>>> for (i=1:i<52:i++) {
>>> j = random(i+1) - 1;
>>> pack_of_cards-->i = pack_of_cards-->j; pack_of_cards-->j = i;
>>> }
>>
>> Minor fix to make sure (pack_of_cards-->i) and (pack_of_cards-->j) are
>> swapped correctly:
>>
>> pack_of_cards-->0 = 0;
>> for (i=1:i<52:i++) {
>> j = random(i+1) - 1;
>> temp = pack_of_cards-->i ;
>> pack_of_cards-->i = pack_of_cards-->j;
>> pack_of_cards-->j = temp;
>> }
>
> Your algorithm fails to initialize the array, hence all locations but one
> would be uninitialized (either garbage or 0). The algorithm provided by
> Samwyse both initializes and shuffles in one pass.

Oops, I forgot that bit at the beginning:

for (i=0:i<52:i++) pack_of_cards-->i = i;

Basically I was reacting to the line:

pack_of_cards-->i = pack_of_cards-->j; pack_of_cards-->j = i;

... which would not really swap poc-->i with poc-->j as intended ...

Thanks for the correction,

David Fisher


Andrew Plotkin

unread,
Jun 9, 2005, 11:15:03 PM6/9/05
to
The server was unavailable most of this past day, due to ISP problems.
It's back now.

Graham Holden

unread,
Jun 10, 2005, 6:57:41 AM6/10/05
to
On Thu, 9 Jun 2005 16:07:08 -0400, Ross Presser
<rpre...@NOSPAMgmail.com.invalid> wrote:

>An overachieving interpereter writer could use a cryptographically strong
>RNG instead of libc's random() if they wanted.

Wrong.

A "real" overachieving interpreter writer would send a request to
http://www.fourmilab.ch/hotbits/generate.html.

Matthew Russotto

unread,
Jun 10, 2005, 11:50:42 AM6/10/05
to
In article <a8sia19ckar1i3q9e...@4ax.com>,

Graham Holden <lo...@bottom.of.post> wrote:
>On Thu, 9 Jun 2005 16:07:08 -0400, Ross Presser
><rpre...@NOSPAMgmail.com.invalid> wrote:
>
>>An overachieving interpereter writer could use a cryptographically strong
>>RNG instead of libc's random() if they wanted.
>
>Wrong.
>
>A "real" overachieving interpreter writer would send a request to
>http://www.fourmilab.ch/hotbits/generate.html.

My hardware Z-machine* comes with its own radioactive source. No need for
possibly-faked, definitely insecure network hotbits.

*Not available in the United States, Canada, or most of Europe due to pesky
safety regulations.
--
Darth Tel: "You can defeat Emperor Gates. He has forseen it. Join me,
and together we will rule the Galaxy as father and son!"

Steve Chipwalker, hanging on by his fingernails: "Sure thing, Pop. Just pull
me up, give me a laptop, and we'll go axe your boss"

-- Megahertz Wars, Episode V, "Finale".

Richard Bos

unread,
Jun 11, 2005, 4:19:00 PM6/11/05
to
Ross Presser <rpre...@NOSPAMgmail.com.invalid> wrote:

> On Thu, 09 Jun 2005 17:09:32 GMT, Richard Bos wrote:
>
> > Andrew Plotkin <erky...@eblong.com> wrote:
> >
> >> Here, Ross Presser <rpre...@nospamgmail.com.invalid> wrote:
> >>> What do you mean by "system-level random number generator"?
> >>
> >> The one in libc.
> >
> > Which libc? The one on MacOS 9? The one on MS Windows? On a Revo?
>

> I believe he meant what I originally thought, that inform's random()
> request is supplied by the interpreter, and whoever wrote the interpreter
> most likely relied on libc.

No, it relied on a C library - if it's written in C at all. Only
Unix/POSIX-derived compilers call their C library libc, AFAIAA. Others
generally do not - for example, Pelles C calls it ctr.lib or crtmt.lib,
apparently depending on your compiler options.

> An overachieving interpereter writer could use a cryptographically strong
> RNG instead of libc's random() if they wanted.

Only libc is guaranteed to have random(), though. All C implementations
must have rand(), which behaves differently - for one, unlike random(),
it's allowed to be cryptographically strong, although of course few are.

Richard

Andrew Plotkin

unread,
Jun 11, 2005, 5:10:44 PM6/11/05
to
Here, Richard Bos <r...@hoekstra-uitgeverij.nl> wrote:
> Ross Presser <rpre...@NOSPAMgmail.com.invalid> wrote:
>
> > On Thu, 09 Jun 2005 17:09:32 GMT, Richard Bos wrote:
> >
> > > Andrew Plotkin <erky...@eblong.com> wrote:
> > >
> > >> Here, Ross Presser <rpre...@nospamgmail.com.invalid> wrote:
> > >>> What do you mean by "system-level random number generator"?
> > >>
> > >> The one in libc.
> > >
> > > Which libc? The one on MacOS 9? The one on MS Windows? On a Revo?
> >
> > I believe he meant what I originally thought, that inform's random()
> > request is supplied by the interpreter, and whoever wrote the interpreter
> > most likely relied on libc.
>
> No, it relied on a C library - if it's written in C at all. Only
> Unix/POSIX-derived compilers call their C library libc, AFAIAA. Others
> generally do not - for example, Pelles C calls it ctr.lib or crtmt.lib,
> apparently depending on your compiler options.

In fact, I meant just what Ross said. I was using "libc" as a generic
term for the C library available on the system. Or one of them, if
there is more than one -- there isn't going to be any significant
difference between (say) the RNG in OSX's Posix lib and the one in its
Carbon Mac toolkit. If you think it's confusing to call those "libc",
then fine.

I will correct myself about interpreters written in Python and Perl,
which (now that I think about it) implement their own RNGs. (At least,
Python does, and I think Perl does.) I can't remember about Java.
These are not, however, the common cases.

ethan...@gmail.com

unread,
Jun 16, 2005, 1:55:43 PM6/16/05
to
Andrew Plotkin wrote:
> I will correct myself about interpreters written in Python and Perl,
> which (now that I think about it) implement their own RNGs. (At least,
> Python does, and I think Perl does.) I can't remember about Java.
> These are not, however, the common cases.

Or assembler (I'm helping to debug a new one even as we speak... look
for an announcement when it's ready to release, but just today it seems
to be able correctly play vast swaths of Zork I (v3 only so far)).

OTOH, I'm glad I stumbled onto this thread - I will be sure to put some
effort into scrutinizing this new interpreter's RNG.

-ethan

Reply all
Reply to author
Forward
0 new messages