首页 > 其他分享 >Programming abstractions in C阅读笔记p111-p113: boilerplate

Programming abstractions in C阅读笔记p111-p113: boilerplate

时间:2023-08-15 13:00:53浏览次数:37  
标签:function p113 p111 boilerplate RAND MAX random high low

《Programming Abstractions In C》学习第47天,p111-p113,总结如下:

一、技术总结 1.boilerplate

/*
 * File: random.h
 * Version: 1.0
 * Last modified on Fri Jul 22 16:44:36 1994 by eroberts
 * -----------------------------------------------------
 * This interface provides several functions for generating
 * pseudo-random numbers.
 */

#ifndef _random_h
#define _random_h

#include "genlib.h"
#include <stdlib.h>

/*
 * Constant: RAND_MAX
 * ------------------
 * Unfortunately, several libraries that supposedly conform to
 * the ANSI standard do not define RAND_MAX in <stdlib.h>.  To
 * reduce portability problems, this interface defines RAND_MAX
 * to be the largest positive integer if it is undefined.
 */

#ifndef RAND_MAX
#  define RAND_MAX ((int) ((unsigned) ~0 >> 1))
#endif

/*
 * Function: Randomize
 * Usage: Randomize();
 * -------------------
 * This function sets the random seed so that the random sequence
 * is unpredictable.  During the debugging phase, it is best not
 * to call this function, so that program behavior is repeatable.
 */

void Randomize(void);

/*
 * Function: RandomInteger
 * Usage: n = RandomInteger(low, high);
 * ------------------------------------
 * This function returns a random integer in the range low to high,
 * inclusive.
 */

int RandomInteger(int low, int high);

/*
 * Function: RandomReal
 * Usage: d = RandomReal(low, high);
 * ---------------------------------
 * This function returns a random real number in the half-open
 * interval [low .. high), meaning that the result is always
 * greater than or equal to low but strictly less than high.
 */

double RandomReal(double low, double high);

/*
 * Function: RandomChance
 * Usage: if (RandomChance(p)) . . .
 * ---------------------------------
 * The RandomChance function returns TRUE with the probability
 * indicated by p, which should be a floating-point number between
 * 0 (meaning never) and 1 (meaning always).  For example, calling
 * RandomChance(.30) returns TRUE 30 percent of the time.
 */

bool RandomChance(double p);

#endif

p113,These three lines are often referred to as interface boilerplate。boilerplate这个词会在计算机相关的教材中会经常看到,英文的意思是:“text that can be copied and used in computer program,with only small changes.”(模板),之所以叫模板,是因为在每个头文件中都有这三句。这个单词不难理解,关键是通过此次的教材对这个单词有一个具体的、形象的记录,当提到这个单词,就知道具体指的是什么。

二、英语总结

1.roll a die一句里面的die是什么意思? 答:die: n.a small cube with a different number of spots on each side.(骰子),所以roll a die的就是"掷骰子"。

2.along with语法

答:along with在表示伴随、以及或连同等意思时,两者之间无先后顺序,可能在前也可能在后。这点与follow不同。示例:For each of these functions, the interface contains one-line prototype along with a comment that describe the purpose of the function from the perspective of clients.

3.up to 语法 答:原文:The line:

#ifndef _random_h

cause the compiler to skip any text up to the #endif line if the the symbol _random_h has been previously defined。

up to短语主要有两种用法:

(1)adv. used to say that sth is less than or equal to but not more than a stated value。

(2)adv. until。

都表示的是“程度”,而不是“方向”。

三、参考资料

1.编程

1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414

2.英语

1)Etymology Dictionary:https://www.etymonline.com

2)Cambridage Dictionary:https://dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)

标签:function,p113,p111,boilerplate,RAND,MAX,random,high,low
From: https://blog.51cto.com/u_15137915/7087568

相关文章

  • P1137 旅行计划
    \(P1137\)旅行计划这个题,我们根据题意是不是知道这个是一个\(DAG\),我们需要计算的是以城市\(i\)为终点最多能够游览多少个城市;这个是不是也是在一个拓扑序上做一个简单的\(dp\)就行了,我们记录一下最大值即可;#include<bits/stdc++.h>usingnamespacestd;constintN=1......
  • P1115 最大子段和 一维动态规划
    #include<iostream>#include<cmath>usingnamespacestd;longlongn,a[200005],dp[200005],ans;intmain(){cin>>n;for(inti=1;i<=n;i++){cin>>a[i];}dp[1]=a[1];ans=a[1];for(inti=2;i<......
  • P1134高精度
    #include<bits/stdc++.h>usingnamespacestd;intmain(){intN;while(cin>>N){inta[3001]={0};inti=0;a[0]=1;while(N){for(i=0;i<3001;i++){......
  • P1119 灾后重建
    题目地址题意:给出n个村庄的灾后重建所需时间和m条双向路和它们的路径长,进行q次询问,每次询问两个村庄在时间t时的最短的路径,且路径上所有村庄都已重建,如果不存在或者t时两......
  • 洛谷P1115 最大子段和
    题目传送门题目描述给出一个长度为 n 的序列 a,选出其中连续且非空的一段使得这段和最大。输入格式第一行是一个整数,表示序列的长度 n。第二行有 n 个整数,第......
  • P1131 [ZJOI2007] 时态同步
    P1131[ZJOI2007]时态同步-洛谷|计算机科学教育新生态(luogu.com.cn)这更多是一个思维题   看到上面这副图,我们的想法是先让1→2和1→3拉伸到1→4的深度,再......
  • P1115 最大子段和
    P1115最大子段和最大子段和题目描述给出一个长度为n的序列a,选出其中连续且非空的一段使得这段和最大。输入格式第一行是一个整数,表示序列的长度n。第二行有n......
  • 适用于AbpBoilerplate的RocketChat Api库
    RocketChat适用于AbpBoilerplate的RocketChatApi库Rocket.Chat是一个免费、开源、可扩展、高度可定制且安全的平台,可让您与团队进行交流和协作、共享文件和实时聊天(h......
  • P1138 第 k 小整数
    第k小整数题目描述现有n个正整数,要求出这n个正整数中的第k个最小整数(相同大小的整数只计算一次)。输入格式第一行为n和k;第二行开始为n个正整数的值,整数......
  • P1115 最大子段和
    https://www.luogu.com.cn/problem/P1115动态规划分析:如果前面的子段加上第i个数是变大的就加上,如果变小状态表示:f[i]表示到i个数字位置的最大子段和的最大值状态计算:f......