px普贤教程PuXian
普贤教程 › 包参考

faker 包

假数据生成(演示/测试夹具)

项值
包名faker
版本0.2.0
可用版本0.1.0 / 0.2.0
入口faker.px
分类文本与中文处理
文件数 / 行数1 / 270

安装与引入

bash
pxpkg init          # 首次
pxpkg add faker@0.2.0
pxpkg install
px
import faker
所属分类教程:文本与中文处理

公开接口

函数参数
fa_randseed
fa_rangeseed, lo, hi
fa_digitsseed, n
fa_surnameseed
fa_givenseed
fa_nameseed
fa_phoneseed
fa_emailseed
fa_sentenceseed, n
fa_uuid
fa_uuid_fromhex16
其余 18 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
fa_provinceseed
fa_cityseed
fa_addressseed
fa_yearseed, lo = 2000, hi = 2026
fa_monthseed
fa_dayseed
fa_dateseed, lo = 2000, hi = 2026
fa_timeseed
fa_companyseed
fa_jobseed
fa_color_hexseed
fa_color_rgbseed
fa_ipv4seed
fa_user_agentseed
fa_credit_cardseed
fa_paragraphseed, sentences = 3
fa_boolseed
fa_passwordseed, length = 12

包内说明(源码头注释)

text
============================================================
普贤生态库:registry/faker —— 假数据生成(演示/测试夹具)
------------------------------------------------------------
纯函数库(无 IO、无状态;fa_uuid 除外,依赖 os_random_hex),
编译(px build)与解释(px run)双模式一致。
确定性 API:每个函数吃入种子 int,返回 [新种子, 值];
fa_rand(seed) / fa_range(seed, lo, hi) / fa_digits(seed, n)
fa_name(seed)    → [新种子, "姓 名"]
fa_surname(seed) / fa_given(seed)
fa_phone(seed)   → [新种子, "1xx-xxxx-xxxx"](第二位 3-9)
fa_email(seed)   → [新种子, "name@example.com"]
fa_sentence(seed, n) → [新种子, n 个词组成的句子]
随机 API(不可复现,仅格式确定):
fa_uuid()        → v4 UUID 串(os_random_hex)
fa_uuid_from(hex16) → v4 UUID 串(给定 16 字节 hex,测试用)
说明:
- PRNG 用 splitmix64 风格(64 位乘加 + 2^64 回绕,两模式一致)
- 词表较小(写库规范 <500 行);性别不区分;域名固定 example.com
============================================================
---- PRNG(splitmix64 风格;i64 乘法/加法按 2^64 回绕) ----