Skip to Content
R语言实战编程
book

R语言实战编程

by Garrett Grolemund
July 2025
Intermediate to advanced
252 pages
2h 38m
Chinese
O'Reilly Media, Inc.
Content preview from R语言实战编程

第 III 部分:项目 3:老虎机 项目 3:老虎机

老虎机是现代赌场中最受欢迎的游戏。如果你从未见过老虎机,那么它就像一个侧面有杠杆的街机游戏。只需支付少量费用,您就可以拉动杠杆,机器就会随机生成三个符号的组合。如果出现正确的组合,您就能赢得奖金,甚至是大奖。

老虎机能为赌场带来丰厚的利润,因为它们的赔率非常低。在许多游戏中,如 21 点和轮盘赌,赔率只是稍微对赌场有利。从长远来看,赌客在这些游戏上每花费 1 美元,赌场就会返还 97 到 98 美分的奖金。对于老虎机,赌场通常只返还 90 到 95 美分,其余的归赌场所有。如果这看起来不光明正大,请记住,老虎机是赌场里最受欢迎的游戏之一,似乎很少有人会介意。而且,如果考虑到州彩票的派彩率更接近 50 美分,老虎机看起来也没那么糟糕。

在这个项目中,您将仿照加拿大马尼托巴省一些真实的视频彩票终端机,制造一台真正的、可以工作的老虎机。在 20 世纪 90 年代,这些终端机曾是丑闻的源头。您将通过编写一个程序来重现老虎机,从而了解这一丑闻的真相。然后,您将进行一些计算并运行一些模拟,以揭示老虎机的真实赔率。

这个项目将教会你如何用 R 语言编写程序和运行模拟:

  • 使用实用策略设计程序

  • 使用ifelse 语句告诉 R 在什么时候做什么

  • 创建查找表来查找数值

  • 使用forwhilerepeat 循环自动执行重复操作

  • 使用 S3 方法--R 的面向对象编程版本

  • 测量 R 代码的速度

  • 编写快速的向量化 R 代码

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

The Three Traps That Stymie Reinvention

The Three Traps That Stymie Reinvention

Ryan Raffaelli
The Human Factor in AI-Based Decision-Making

The Human Factor in AI-Based Decision-Making

Philip Meissner, Christoph Keding
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
Coaching for High Performance

Coaching for High Performance

MIT Sloan Management Review

Publisher Resources

ISBN: 9798341663121