-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path51a7.html
624 lines (575 loc) · 93.1 KB
/
51a7.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"><title>java随机数介绍以及生成随机日期 | 伴随的小站</title><meta name="keywords" content="JAVA,工具类"><meta name="author" content="伴随"><meta name="copyright" content="伴随"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#18171d"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-touch-fullscreen" content="yes"><meta name="apple-mobile-web-app-title" content="java随机数介绍以及生成随机日期"><meta name="application-name" content="java随机数介绍以及生成随机日期"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="#18171d"><meta property="og:type" content="article"><meta property="og:title" content="java随机数介绍以及生成随机日期"><meta property="og:url" content="https://ctext.top/51a7.html"><meta property="og:site_name" content="伴随的小站"><meta property="og:description" content="生成一个随机日期 1234567891011public static Date randomTime(Date startTime, Date endTime) &#123; &#x2F;&#x2F; 获取时间区间的起始毫秒值和结束毫秒值 long startMillis &#x3D; startTime.getT"><meta property="og:locale" content="zh-CN"><meta property="og:image" content="https://up.ctext.top/article/2024/10/tools2.png"><meta property="article:author" content="伴随"><meta property="article:tag"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://up.ctext.top/article/2024/10/tools2.png"><meta name="description" content="生成一个随机日期 1234567891011public static Date randomTime(Date startTime, Date endTime) &#123; &#x2F;&#x2F; 获取时间区间的起始毫秒值和结束毫秒值 long startMillis &#x3D; startTime.getT"><link rel="shortcut icon" href="https://up.ctext.top/favicon.svg"><link rel="canonical" href="https://ctext.top/51a7.html"><link rel="preconnect" href="//cdn.cbd.int"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="xxx"/><meta name="baidu-site-verification" content="codeva-ulCeD8b6u5"/><meta name="msvalidate.01" content="xxx"/><meta name="sogou_site_verification" content="YdTw3LB3JQ"/><meta name="360-site-verification" content="5f481d0e3172c0894747aba683bb1191"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.cbd.int/@fortawesome/fontawesome-free@6.4.0/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/node-snackbar@0.1.16/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/@fancyapps/ui@5.0.28/dist/fancybox/fancybox.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/anzhiyu-theme-static@1.0.0/swiper/swiper.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?643616874a8f4f5ed38e6146dfd84820";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = {
linkPageTop: undefined,
peoplecanvas: undefined,
postHeadAiDescription: {"enable":true,"gptName":null,"mode":"tianli","switchBtn":false,"btnLink":null,"randomNum":3,"basicWordCount":1000,"key":"XlJ1hsZTEze","Referer":"/"},
diytitle: {"enable":true,"leaveTitle":"分享使快乐加倍!(´▽`)","backTitle":"慢慢看~ヾ(•ω•`)o"},
LA51: undefined,
greetingBox: {"enable":true,"default":"晚上好👋","list":[{"greeting":"晚安啦🌙,做个好梦,期待明天的美好!😴💤","startTime":0,"endTime":6},{"greeting":"早上好🌞,新的一天,愿你充满活力和正能量!💪🌈","startTime":6,"endTime":10},{"greeting":"上午好👋,工作/学习加油,期待你的出色表现!🌟📚","startTime":10,"endTime":12},{"greeting":"午餐时间到🍽️,好好吃饭,下午继续加油!🍛💼","startTime":12,"endTime":14},{"greeting":"下午好👋,午后时光,放松心情,享受片刻宁静。☕️💆♀️","startTime":14,"endTime":17},{"greeting":"傍晚好,一天即将结束,为自己点个赞吧!👍🎉","startTime":17,"endTime":19},{"greeting":"晚餐时间啦🍲,享受美食,犒劳一下自己吧!🍽️🥳","startTime":19,"endTime":21},{"greeting":"晚上好🌃,夜晚的时光,放松身心,好好休息吧!🛌💤","startTime":21,"endTime":24}]},
twikooEnvId: '',
commentBarrageConfig:undefined,
music_page_default: "nav_music",
root: '/',
preloader: {"source":3},
friends_vue_info: undefined,
navMusic: true,
mainTone: {"mode":"api","api":"https://color.ctext.top/api?img=","cover_change":true},
authorStatus: {"skills":["🤖️ 数码科技爱好者","🔍 分享与热心帮助","🏠 智能家居小能手","🔨 设计开发一条龙"]},
algolia: undefined,
localSearch: undefined,
translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简","rightMenuMsgToTraditionalChinese":"转为繁体","rightMenuMsgToSimplifiedChinese":"转为简体"},
noticeOutdate: undefined,
highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":330},
copy: {
success: '复制成功',
error: '复制错误',
noSupport: '浏览器不支持'
},
relativeDate: {
homepage: false,
simplehomepage: true,
post: false
},
runtime: '天',
date_suffix: {
just: '刚刚',
min: '分钟前',
hour: '小时前',
day: '天前',
month: '个月前'
},
copyright: {"copy":true,"copyrightEbable":false,"limitCount":50,"languages":{"author":"作者: 伴随","link":"链接: ","source":"来源: 伴随的小站","info":"著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。","copySuccess":"复制成功,复制和转载请标注本文地址"}},
lightbox: 'fancybox',
Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#425AEF","bgDark":"#1f1f1f","position":"top-center"},
source: {
justifiedGallery: {
js: 'https://cdn.cbd.int/flickr-justified-gallery@2.1.2/dist/fjGallery.min.js',
css: 'https://cdn.cbd.int/flickr-justified-gallery@2.1.2/dist/fjGallery.css'
}
},
isPhotoFigcaption: false,
islazyload: true,
isAnchor: false,
shortcutKey: undefined,
autoDarkmode: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
configTitle: '伴随的小站',
title: 'java随机数介绍以及生成随机日期',
postAI: 'true',
pageFillDescription: '生成一个随机日期, JAVA生成随机数API, 1. java.util.Random, 2. java.util.concurrent.ThreadLocalRandom, 3. java.security.SecureRandom, 4. Math.random(), 5. java.util.Randomints (Java 8+), 总结, 最后再说一下Hutool中的随机数API生成一个随机日期获取时间区间的起始毫秒值和结束毫秒值使用在区间内生成一个随机的毫秒值返回一个新的随机时间工具类比较简单这里就不多介绍了这篇文章主要介绍一下生成随机数的生成随机数是中最常用的随机数生成器属于伪随机数生成器提供了一系列方法来生成不同类型的随机数生成随机整数生成到之间的随机整数生成随机长整数生成到之间的随机小数是的线程安全版本适合在多线程环境中使用它的性能更好因为它为每个线程创建一个独立的随机数生成器生成随机整数生成到之间的随机整数生成随机长整数生成到之间的随机小数是专门设计用于生成加密强度的随机数它比更安全因为它使用的是加密算法生成的随机数适合需要高安全性的场景例如生成加密密钥会话标识符等生成随机整数生成到之间的随机整数生成随机字节数组是中生成到之间的双精度浮点数的简便方法它是类的一个简化接口内部实际上使用的是类的实例生成到之间的随机小数从开始类新增了一些流式可以用来生成随机数流这对于生成一组随机数非常有用生成一个包含个随机整数的流生成指定范围内的随机整数流总结随机数生成器特点适用场景性能伪随机数生成器使用线性同余法支持多种随机数类型生成普通单线程场景中线程安全性能优于适合多线程环境多线程场景高安全性高难以预测适合加密生成密钥等场景安全性要求高的场景加密认证等低简单易用只能生成的随机数生成简单的随机小数中支持流式生成随机数适合生成多个随机数批量生成随机数中最后再说一下中的随机数库中的提供了一系列生成随机数的方法它基于的实现因此具备线程安全性能高效的特性在性能和使用便捷性上与原生的随机数生成工具相比有一些优势尤其是简化了常见的随机数生成操作用法很多这里简单写几个生成一个随机整数生成到之间的随机整数生成随机长整数生成指定长度的随机字符串用法很多基本上我们常用的生成方式它都能提供使用简单无需创建对象直接调用不支持加密强度的随机数生成',
isPost: true,
isHome: false,
isHighlightShrink: false,
isToc: true,
postUpdate: '2025-01-03 15:32:43',
postMainColor: '#d287b8',
}</script><noscript><style type="text/css">
#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#recent-posts time,
#post-meta time {
display: inline !important
}
</style></noscript><script>(win=>{
win.saveToLocal = {
set: (key, value, ttl) => {
if (ttl === 0) return
const now = Date.now()
const expiry = now + ttl * 86400000
const item = {
value,
expiry
}
localStorage.setItem(key, JSON.stringify(item))
},
get: key => {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = Date.now()
if (now > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
Object.keys(attr).forEach(key => {
script.setAttribute(key, attr[key])
})
document.head.appendChild(script)
})
win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = url
if (id) link.id = id
link.onerror = reject
link.onload = link.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
link.onload = link.onreadystatechange = null
resolve()
}
document.head.appendChild(link)
})
win.activateDarkMode = () => {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#18171d')
}
}
win.activateLightMode = () => {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#f7f9fe')
}
}
const t = saveToLocal.get('theme')
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
if (t === undefined) {
if (isLightMode) activateLightMode()
else if (isDarkMode) activateDarkMode()
else if (isNotSpecified || hasNoSupport) {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
isNight ? activateDarkMode() : activateLightMode()
}
window.matchMedia('(prefers-color-scheme: dark)').addListener(e => {
if (saveToLocal.get('theme') === undefined) {
e.matches ? activateDarkMode() : activateLightMode()
}
})
} else if (t === 'light') activateLightMode()
else activateDarkMode()
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
const detectApple = () => {
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
document.documentElement.classList.add('apple')
}
}
detectApple()
})(window)</script><link rel="stylesheet" href="/css/font.css"><link rel="stylesheet" href="/css/welcome.css"><link rel="stylesheet" href="/css/imgloaded.css"><link rel="stylesheet" href="/css/hideRolling.css"><link rel="stylesheet" href="/css/countdown.css"><link rel="stylesheet" href="/css/essay-animation.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 7.3.0"></head><body data-type="anzhiyu"><div id="web_bg"></div><div id="an_music_bg"></div><div id="loading-box" onclick="document.getElementById("loading-box").classList.add("loaded")"><div class="loading-bg"><img class="loading-img nolazyload" alt="加载头像" src="https://up.ctext.top/avatar.png"/><div class="loading-image-dot"></div></div></div><script>const preloader = {
endLoading: () => {
document.getElementById('loading-box').classList.add("loaded");
},
initLoading: () => {
document.getElementById('loading-box').classList.remove("loaded")
}
}
window.addEventListener('load',()=> { preloader.endLoading() })
setTimeout(function(){preloader.endLoading();},10000)
if (true) {
document.addEventListener('pjax:send', () => { preloader.initLoading() })
document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-theme-static@1.1.10/progress_bar/progress_bar.css"/><script async="async" src="https://cdn.cbd.int/pace-js@1.2.4/pace.min.js" data-pace-options="{ "restartOnRequestAfter":false,"eventLag":false}"></script><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><div id="nav-group"><span id="blog_name"><div class="back-home-button"><i class="anzhiyufont anzhiyu-icon-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">关于</div><div class="back-menu-list"><a class="back-menu-item" href="/about/" title="我"><img class="back-menu-item-icon" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/ico/orange.svg" alt="我"/><span class="back-menu-item-text">我</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">博客</div><div class="back-menu-list"><a class="back-menu-item" href="/album/" title="我的相册"><img class="back-menu-item-icon" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/ico/strawberry.svg" alt="我的相册"/><span class="back-menu-item-text">我的相册</span></a><a class="back-menu-item" href="/essay/" title="记录生活"><img class="back-menu-item-icon" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/ico/apple.svg" alt="记录生活"/><span class="back-menu-item-text">记录生活</span></a></div></div></div></div><a id="site-name" href="/" accesskey="h"><div class="title">伴随的小站</div><i class="anzhiyufont anzhiyu-icon-house-chimney"></i></a></span><div class="mask-name-container"><div id="name-container"><a id="page-name" href="javascript:anzhiyu.scrollToDest(0, 500)">PAGE_NAME</a></div></div><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 文章</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/"><i class="anzhiyufont anzhiyu-icon-grip-vertical faa-tada" style="font-size: 0.9em;"></i><span> 主页</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/archives/"><i class="anzhiyufont anzhiyu-icon-box-archive faa-tada" style="font-size: 0.9em;"></i><span> 总览</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><i class="anzhiyufont anzhiyu-icon-shapes faa-tada" style="font-size: 0.9em;"></i><span> 分类</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><i class="anzhiyufont anzhiyu-icon-tags faa-tada" style="font-size: 0.9em;"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 我的</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/growth.html"><i class="anzhiyufont anzhiyu-icon-heartbeat faa-tada" style="font-size: 0.9em;"></i><span> 博客岁月</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/music/"><i class="anzhiyufont anzhiyu-icon-music faa-tada" style="font-size: 0.9em;"></i><span> 音乐馆</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/"><i class="anzhiyufont anzhiyu-icon-images faa-tada" style="font-size: 0.9em;"></i><span> 相册集</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/essay/"><i class="anzhiyufont anzhiyu-icon-lightbulb faa-tada" style="font-size: 0.9em;"></i><span> 记录生活</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 小工具</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/air-conditioner/"><i class="anzhiyufont anzhiyu-icon-fan faa-tada" style="font-size: 0.9em;"></i><span> 小空调</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/gradation/"><i class="anzhiyufont anzhiyu-icon-envelope faa-tada" style="font-size: 0.9em;"></i><span> 渐变背景生成</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/9abe.html"><i class="anzhiyufont anzhiyu-icon-artstation faa-tada" style="font-size: 0.9em;"></i><span> tag-plugins文档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/nav"><i class="anzhiyufont anzhiyu-icon-link faa-tada" style="font-size: 0.9em;"></i><span> 网址导航</span></a></li><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://map.ctext.top"><i class="anzhiyufont anzhiyu-icon-keyboard faa-tada" style="font-size: 0.9em;"></i><span> 飞车随机选图工具</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 关于</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/about/"><i class="anzhiyufont anzhiyu-icon-paper-plane faa-tada" style="font-size: 0.9em;"></i><span> 关于自己</span></a></li><li><a class="site-page child faa-parent animated-hover" href="javascript:toRandomPost()"><i class="anzhiyufont anzhiyu-icon-shoe-prints1 faa-tada" style="font-size: 0.9em;"></i><span> 随便逛逛</span></a></li></ul></div></div></div><div id="nav-right"><div class="nav-button" id="randomPost_button"><a class="site-page" onclick="toRandomPost()" title="随机前往一个文章" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-dice"></i></a></div><input id="center-console" type="checkbox"/><label class="widget" for="center-console" title="中控台" onclick="anzhiyu.switchConsole();"><i class="left"></i><i class="widget center"></i><i class="widget right"></i></label><div id="console"><div class="console-card-group-reward"><ul class="reward-all console-card"><li class="reward-item"><a href="https://up.ctext.top/pay/wx.png" target="_blank"><img class="post-qr-code-img" alt="微信" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/pay/wx.png"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://up.ctext.top/pay/zfb.png" target="_blank"><img class="post-qr-code-img" alt="支付宝" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/pay/zfb.png"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div><div class="console-card-group"><div class="console-card-group-left"><div class="console-card" id="card-newest-comments"><div class="card-content"><div class="author-content-item-tips">互动</div><span class="author-content-item-title"> 最新评论</span></div><div class="aside-list"><span>正在加载中...</span></div></div></div><div class="console-card-group-right"><div class="console-card tags"><div class="card-content"><div class="author-content-item-tips">音乐</div><span class="author-content-item-title">灵魂的碰撞💥</span></div></div><div class="console-card history"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-box-archiv"></i><span>文章</span></div><div class="card-archives"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-archive"></i><span>归档</span><a class="card-more-btn" href="/archives/" title="查看更多">
<i class="anzhiyufont anzhiyu-icon-angle-right"></i></a></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/11/"><span class="card-archive-list-date">十一月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">1</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/10/"><span class="card-archive-list-date">十月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">2</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/08/"><span class="card-archive-list-date">八月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">3</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/07/"><span class="card-archive-list-date">七月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">2</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/06/"><span class="card-archive-list-date">六月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">5</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/05/"><span class="card-archive-list-date">五月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">2</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/04/"><span class="card-archive-list-date">四月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">3</span><span>篇</span></div></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/03/"><span class="card-archive-list-date">三月 2024</span><div class="card-archive-list-count-group"><span class="card-archive-list-count">4</span><span>篇</span></div></a></li></ul></div><hr/></div></div></div><div class="button-group"><div class="console-btn-item"><a class="darkmode_switchbutton" title="显示模式切换" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-moon"></i></a></div><div class="console-btn-item" id="consoleHideAside" onclick="anzhiyu.hideAsideBtn()" title="边栏显示控制"><a class="asideSwitch"><i class="anzhiyufont anzhiyu-icon-arrows-left-right"></i></a></div><div class="console-btn-item" id="consoleMusic" onclick="anzhiyu.musicToggle()" title="音乐开关"><a class="music-switch"><i class="anzhiyufont anzhiyu-icon-music"></i></a></div></div><div class="console-mask" onclick="anzhiyu.hideConsole()" href="javascript:void(0);"></div></div><div class="nav-button" id="nav-totop"><a class="totopbtn" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i><span id="percent" onclick="anzhiyu.scrollToDest(0,500)">0</span></a></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);" title="切换"><i class="anzhiyufont anzhiyu-icon-bars"></i></a></div></div></div></nav><div id="post-info"><div id="post-firstinfo"><div class="meta-firstline"><a class="post-meta-original">原创</a><span class="post-meta-categories"><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-inbox post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/" itemprop="url">技术教程</a></span><span class="article-meta tags"><a class="article-meta__tags" href="/tags/JAVA/" tabindex="-1" itemprop="url"> <span> <i class="anzhiyufont anzhiyu-icon-hashtag"></i>JAVA</span></a><a class="article-meta__tags" href="/tags/%E5%B7%A5%E5%85%B7%E7%B1%BB/" tabindex="-1" itemprop="url"> <span> <i class="anzhiyufont anzhiyu-icon-hashtag"></i>工具类</span></a></span></div></div><h1 class="post-title" itemprop="name headline">java随机数介绍以及生成随机日期</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="anzhiyufont anzhiyu-icon-calendar-days post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" itemprop="dateCreated datePublished" datetime="2024-10-14T12:16:33.000Z" title="发表于 2024-10-14 20:16:33">2024-10-14</time><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-history post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" itemprop="dateCreated datePublished" datetime="2025-01-03T07:32:43.481Z" title="更新于 2025-01-03 15:32:43">2025-01-03</time></span></div><div class="meta-secondline"><span class="post-meta-separator"></span><span class="post-meta-wordcount"><i class="anzhiyufont anzhiyu-icon-file-word post-meta-icon" title="文章字数"></i><span class="post-meta-label" title="文章字数">字数总计:</span><span class="word-count" title="文章字数">1k</span><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-clock post-meta-icon" title="阅读时长"></i><span class="post-meta-label" title="阅读时长">阅读时长:</span><span>3分钟</span></span><span class="post-meta-separator"></span><span class="post-meta-pv-cv" id="" data-flag-title="java随机数介绍以及生成随机日期"><i class="anzhiyufont anzhiyu-icon-fw-eye post-meta-icon"></i><span class="post-meta-label" title="阅读量">阅读量:</span><span id="busuanzi_value_page_pv"><i class="anzhiyufont anzhiyu-icon-spinner anzhiyu-spin"></i></span></span><span class="post-meta-separator"> </span><span class="post-meta-position" title="作者IP属地为北京"><i class="anzhiyufont anzhiyu-icon-location-dot"></i>北京</span></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section><div id="post-top-cover"><img class="nolazyload" id="post-top-bg" src="https://up.ctext.top/article/2024/10/tools2.png"></div></header><main id="blog-container"><div class="layout" id="content-inner"><div id="post"><div class="post-ai-description"><div class="ai-title"><i class="anzhiyufont anzhiyu-icon-bilibili"></i><div class="ai-title-text">AI-摘要(由百度千帆大模型提供生成摘要能力)</div><i class="anzhiyufont anzhiyu-icon-arrow-rotate-right"></i><i class="anzhiyufont anzhiyu-icon-circle-dot" title="朗读摘要"></i><div id="ai-tag">Tianli GPT</div></div><div class="ai-explanation">AI初始化中...</div><div class="ai-btn-box"><div class="ai-btn-item" id="ccnone">介绍自己 🙈</div><div class="ai-btn-item">生成本文简介 👋</div><div class="ai-btn-item">推荐相关文章 📖</div><div class="ai-btn-item">前往主页 🏠</div><div class="ai-btn-item" id="go-tianli-blog">前往爱发电购买</div></div><script data-pjax src="/js/anzhiyu/ai_abstract.js"></script></div><article class="post-content" id="article-container" itemscope itemtype="https://ctext.top/51a7.html"><header><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/" itemprop="url">技术教程</a><a href="/tags/JAVA/" tabindex="-1" itemprop="url">JAVA</a><a href="/tags/%E5%B7%A5%E5%85%B7%E7%B1%BB/" tabindex="-1" itemprop="url">工具类</a><h1 id="CrawlerTitle" itemprop="name headline">java随机数介绍以及生成随机日期</h1><span itemprop="author" itemscope itemtype="http://schema.org/Person">伴随</span><time itemprop="dateCreated datePublished" datetime="2024-10-14T12:16:33.000Z" title="发表于 2024-10-14 20:16:33">2024-10-14</time><time itemprop="dateCreated datePublished" datetime="2025-01-03T07:32:43.481Z" title="更新于 2025-01-03 15:32:43">2025-01-03</time></header><h1>生成一个随机日期</h1>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> Date <span class="title function_">randomTime</span><span class="params">(Date startTime, Date endTime)</span> {</span><br><span class="line"> <span class="comment">// 获取时间区间的起始毫秒值和结束毫秒值</span></span><br><span class="line"> <span class="type">long</span> <span class="variable">startMillis</span> <span class="operator">=</span> startTime.getTime();</span><br><span class="line"> <span class="type">long</span> <span class="variable">endMillis</span> <span class="operator">=</span> endTime.getTime();</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 使用 ThreadLocalRandom 在区间内生成一个随机的毫秒值</span></span><br><span class="line"> <span class="type">long</span> <span class="variable">randomMillis</span> <span class="operator">=</span> ThreadLocalRandom.current().nextLong(startMillis, endMillis);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 返回一个新的随机时间</span></span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Date</span>(randomMillis);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<div class="note info no-icon flat"><p>工具类比较简单,这里就不多介绍了,这篇文章主要介绍一下java生成随机数的API</p>
</div>
<h1>JAVA生成随机数API</h1>
<h2 id="1-java-util-Random">1. java.util.Random</h2>
<p><strong>Random</strong> 是 Java 中最常用的随机数生成器,属于伪随机数生成器(PRNG)。<strong>Random</strong> 提供了一系列方法来生成不同类型的随机数。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">Random</span> <span class="variable">random</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Random</span>();</span><br><span class="line"><span class="type">int</span> <span class="variable">randomInt</span> <span class="operator">=</span> random.nextInt(); <span class="comment">// 生成随机整数</span></span><br><span class="line"><span class="type">int</span> <span class="variable">randomIntInRange</span> <span class="operator">=</span> random.nextInt(<span class="number">100</span>); <span class="comment">// 生成 0 到 99 之间的随机整数</span></span><br><span class="line"><span class="type">long</span> <span class="variable">randomLong</span> <span class="operator">=</span> random.nextLong(); <span class="comment">// 生成随机长整数</span></span><br><span class="line"><span class="type">double</span> <span class="variable">randomDouble</span> <span class="operator">=</span> random.nextDouble(); <span class="comment">// 生成 0.0 到 1.0 之间的随机小数</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="2-java-util-concurrent-ThreadLocalRandom">2. java.util.concurrent.ThreadLocalRandom</h2>
<p><strong>ThreadLocalRandom</strong> 是 <strong>Random</strong> 的线程安全版本,适合在多线程环境中使用。它的性能更好,因为它为每个线程创建一个独立的随机数生成器。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">ThreadLocalRandom</span> <span class="variable">random</span> <span class="operator">=</span> ThreadLocalRandom.current();</span><br><span class="line"><span class="type">int</span> <span class="variable">randomInt</span> <span class="operator">=</span> random.nextInt(); <span class="comment">// 生成随机整数</span></span><br><span class="line"><span class="type">int</span> <span class="variable">randomIntInRange</span> <span class="operator">=</span> random.nextInt(<span class="number">100</span>); <span class="comment">// 生成 0 到 99 之间的随机整数</span></span><br><span class="line"><span class="type">long</span> <span class="variable">randomLong</span> <span class="operator">=</span> random.nextLong(); <span class="comment">// 生成随机长整数</span></span><br><span class="line"><span class="type">double</span> <span class="variable">randomDouble</span> <span class="operator">=</span> random.nextDouble(); <span class="comment">// 生成 0.0 到 1.0 之间的随机小数</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="3-java-security-SecureRandom">3. java.security.SecureRandom</h2>
<p><strong>SecureRandom</strong> 是专门设计用于生成加密强度的随机数。它比 Random 更安全,因为它使用的是加密算法生成的随机数,适合需要高安全性的场景,例如生成加密密钥、会话标识符等</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">SecureRandom</span> <span class="variable">secureRandom</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SecureRandom</span>();</span><br><span class="line"><span class="type">int</span> <span class="variable">randomInt</span> <span class="operator">=</span> secureRandom.nextInt(); <span class="comment">// 生成随机整数</span></span><br><span class="line"><span class="type">int</span> <span class="variable">randomIntInRange</span> <span class="operator">=</span> secureRandom.nextInt(<span class="number">100</span>); <span class="comment">// 生成 0 到 99 之间的随机整数</span></span><br><span class="line"><span class="type">byte</span>[] bytes = <span class="keyword">new</span> <span class="title class_">byte</span>[<span class="number">16</span>];</span><br><span class="line">secureRandom.nextBytes(bytes); <span class="comment">// 生成随机字节数组</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="4-Math-random">4. Math.random()</h2>
<p><strong>Math.random()</strong> 是 Java 中生成 0.0 到 1.0 之间的双精度浮点数的简便方法,它是 <strong>Random</strong> 类的一个简化接口。<strong>Math.random()</strong> 内部实际上使用的是 <strong>Random</strong> 类的实例。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">double</span> <span class="variable">randomDouble</span> <span class="operator">=</span> Math.random(); <span class="comment">// 生成 0.0 到 1.0 之间的随机小数</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="5-java-util-Random-ints-Java-8">5. java.util.Random#ints (Java 8+)</h2>
<p>从 <strong>Java 8</strong> 开始,<strong>Random</strong> 类新增了一些流式 <strong>API</strong>,可以用来生成随机数流,这对于生成一组随机数非常有用。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="type">Random</span> <span class="variable">random</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Random</span>();</span><br><span class="line"><span class="comment">// 生成一个包含 5 个随机整数的流</span></span><br><span class="line">random.ints(<span class="number">5</span>).forEach(System.out::println);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 生成指定范围内的随机整数流</span></span><br><span class="line">random.ints(<span class="number">5</span>, <span class="number">0</span>, <span class="number">100</span>).forEach(System.out::println);</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="总结">总结</h2>
<table>
<thead>
<tr>
<th style="text-align:left">随机数生成器</th>
<th>特点</th>
<th>适用场景</th>
<th>性能</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>Random</code></td>
<td>伪随机数生成器,使用线性同余法,支持多种随机数类型生成。</td>
<td>普通单线程场景</td>
<td>中</td>
</tr>
<tr>
<td style="text-align:left"><code>ThreadLocalRandom</code></td>
<td>线程安全,性能优于 <code>Random</code>,适合多线程环境。</td>
<td>多线程场景</td>
<td>高</td>
</tr>
<tr>
<td style="text-align:left"><code>SecureRandom</code></td>
<td>安全性高,难以预测,适合加密、生成密钥等场景。</td>
<td>安全性要求高的场景(加密、认证等)</td>
<td>低</td>
</tr>
<tr>
<td style="text-align:left"><code>Math.random()</code></td>
<td>简单易用,只能生成 <code>0.0 - 1.0</code> 的 <code>double</code> 随机数。</td>
<td>生成简单的随机小数</td>
<td>中</td>
</tr>
<tr>
<td style="text-align:left"><code>Random#ints</code> (Java 8+)</td>
<td>支持流式生成随机数,适合生成多个随机数。</td>
<td>批量生成随机数</td>
<td>中</td>
</tr>
</tbody>
</table>
<h2 id="最后再说一下Hutool中的随机数API">最后再说一下<strong>Hutool</strong>中的随机数API</h2>
<p><strong>Hutool</strong> 库中的 <strong>RandomUtil</strong> 提供了一系列生成随机数的方法,它基于 <strong>JDK</strong> 的 <strong>ThreadLocalRandom</strong> 实现,因此具备线程安全、性能高效的特性。在性能和使用便捷性上,<strong>RandomUtil</strong> 与 <strong>JDK</strong> 原生的随机数生成工具相比,有一些优势,尤其是简化了常见的随机数生成操作。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 用法很多,这里简单写几个</span></span><br><span class="line"><span class="type">int</span> <span class="variable">randomInt</span> <span class="operator">=</span> RandomUtil.randomInt(); <span class="comment">// 生成一个随机整数</span></span><br><span class="line"><span class="type">int</span> <span class="variable">randomIntInRange</span> <span class="operator">=</span> RandomUtil.randomInt(<span class="number">100</span>); <span class="comment">// 生成 0 到 99 之间的随机整数</span></span><br><span class="line"><span class="type">long</span> <span class="variable">randomLong</span> <span class="operator">=</span> RandomUtil.randomLong(); <span class="comment">// 生成随机长整数</span></span><br><span class="line"><span class="type">String</span> <span class="variable">randomString</span> <span class="operator">=</span> RandomUtil.randomString(<span class="number">10</span>); <span class="comment">// 生成指定长度的随机字符串</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ul>
<li>用法很多,基本上我们常用的生成方式它都能提供</li>
<li>使用简单,无需创建对象,直接调用</li>
<li>不支持加密强度的随机数生成</li>
</ul>
</article><div class="post-copyright"><div class="copyright-cc-box"><i class="anzhiyufont anzhiyu-icon-copyright"></i></div><div class="post-copyright__author_box"><a class="post-copyright__author_img" href="/" title="头像"><img class="post-copyright__author_img_back" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/avatar.png" title="头像" alt="头像"><img class="post-copyright__author_img_front" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/avatar.png" title="头像" alt="头像"></a><div class="post-copyright__author_name">伴随</div><div class="post-copyright__author_desc">请保持那份热爱 奔赴下一场山海</div></div><div class="post-copyright__post__info"><a class="post-copyright__original" title="该文章为原创文章,注意版权协议" href="https://ctext.top/51a7.html">原创</a><a class="post-copyright-title"><span onclick="rm.copyPageUrl('https://ctext.top/51a7.html')">java随机数介绍以及生成随机日期</span></a></div><div class="post-tools" id="post-tools"><div class="post-tools-left"><div class="rewardLeftButton"><div class="post-reward" onclick="anzhiyu.addRewardMask()"><div class="reward-button button--animated" title="赞赏作者"><i class="anzhiyufont anzhiyu-icon-hand-heart-fill"></i>打赏作者</div><div class="reward-main"><div class="reward-all"><span class="reward-title">感谢你赐予我前进的力量</span><ul class="reward-group"><li class="reward-item"><a href="https://up.ctext.top/pay/wx.png" target="_blank"><img class="post-qr-code-img" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/pay/wx.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://up.ctext.top/pay/zfb.png" target="_blank"><img class="post-qr-code-img" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/pay/zfb.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul><a class="reward-main-btn" href="/about/#about-reward" target="_blank"><div class="reward-text">赞赏者名单</div><div class="reward-dec">因为你们的支持让我意识到写文章的价值🙏</div></a></div></div></div><div id="quit-box" onclick="anzhiyu.removeRewardMask()" style="display: none"></div></div><div class="shareRight"><div class="share-link mobile"><div class="share-qrcode"><div class="share-button" title="使用手机访问这篇文章"><i class="anzhiyufont anzhiyu-icon-qrcode"></i></div><div class="share-main"><div class="share-main-all"><div id="qrcode" title="https://ctext.top/51a7.html"></div><div class="reward-dec">使用手机访问这篇文章</div></div></div></div></div><div class="share-link weibo"><a class="share-button" target="_blank" href="https://service.weibo.com/share/share.php?title=java随机数介绍以及生成随机日期&url=https://ctext.top/51a7.html&pic=https://up.ctext.top/article/2024/10/tools2.png" rel="external nofollow noreferrer noopener"><i class="anzhiyufont anzhiyu-icon-weibo"></i></a></div><script>function copyCurrentPageUrl() {
var currentPageUrl = window.location.href;
var input = document.createElement("input");
input.setAttribute("value", currentPageUrl);
document.body.appendChild(input);
input.select();
input.setSelectionRange(0, 99999);
document.execCommand("copy");
document.body.removeChild(input);
}</script><div class="share-link copyurl"><div class="share-button" id="post-share-url" title="复制链接" onclick="copyCurrentPageUrl()"><i class="anzhiyufont anzhiyu-icon-link"></i></div></div></div></div></div><div class="post-copyright__notice"><span class="post-copyright-info">本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ctext.top" target="_blank">伴随的小站</a>!</span></div></div><div class="post-tools-right"><div class="tag_share"><div class="post-meta__box"><div class="post-meta__box__category-list"><a class="post-meta__box__categoryes" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/"><span class="categoryes-punctuation"> <i class="anzhiyufont anzhiyu-icon-inbox"></i></span>技术教程<span class="categoryesPageCount">11</span></a></div><div class="post-meta__box__tag-list"><a class="post-meta__box__tags" href="/tags/JAVA/"><span class="tags-punctuation"> <i class="anzhiyufont anzhiyu-icon-tag"></i></span>JAVA<span class="tagsPageCount">6</span></a><a class="post-meta__box__tags" href="/tags/%E5%B7%A5%E5%85%B7%E7%B1%BB/"><span class="tags-punctuation"> <i class="anzhiyufont anzhiyu-icon-tag"></i></span>工具类<span class="tagsPageCount">3</span></a></div></div><div class="post_share"><div class="social-share" data-image="https://up.ctext.top/article/2024/11/tools3.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.cbd.int/butterfly-extsrc@1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"/><script src="https://cdn.cbd.int/butterfly-extsrc@1.1.3/sharejs/dist/js/social-share.min.js" defer="defer"></script></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/3329.html"><img class="prev-cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/08/tools1.png" onerror="onerror=null;src='https://up.ctext.top/default_bg.png'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">JAVA工具类(一)——生成班次排班记录</div></div></a></div><div class="next-post pull-right"><a href="/dfd4.html"><img class="next-cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/10/idea.png" onerror="onerror=null;src='https://up.ctext.top/default_bg.png'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">IDEA快捷键大全</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="anzhiyufont anzhiyu-icon-thumbs-up fa-fw" style="font-size: 1.5rem; margin-right: 4px"></i><span>喜欢这篇文章的人也看了</span></div><div class="relatedPosts-list"><div><a href="/8a0c.html" title="JAVA表达式解析器———EvalEx"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/11/tools3.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-11-17</div><div class="title">JAVA表达式解析器———EvalEx</div></div></a></div><div><a href="/3329.html" title="JAVA工具类(一)——生成班次排班记录"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/08/tools1.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-08-15</div><div class="title">JAVA工具类(一)——生成班次排班记录</div></div></a></div><div><a href="/dfd4.html" title="IDEA快捷键大全"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/10/idea.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-10-15</div><div class="title">IDEA快捷键大全</div></div></a></div><div><a href="/37ef.html" title="linux下jar启停脚本分享"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/06/jar.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2024-06-12</div><div class="title">linux下jar启停脚本分享</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="anzhiyufont anzhiyu-icon-comments"></i><span> 评论</span></div><div class="comment-randomInfo"><a onclick="anzhiyu.addRandomCommentInfo()" href="javascript:void(0)" style="display: none">匿名评论</a><a href="/privacy" style="margin-left: 4px">隐私政策</a></div></div><div class="comment-wrap"><div><div id="waline-wrap"></div></div></div></div><div class="comment-barrage"></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-content"><div class="author-info__sayhi" id="author-info__sayhi" onclick="anzhiyu.changeSayHelloText()"></div><div class="author-info-avatar"><img class="avatar-img" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-status"><img class="g-status" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://bu.dusays.com/2023/08/24/64e6ce9c507bb.png" alt="status"/></div></div><div class="author-info__description"><div style="line-height:1.38;margin:0.6rem 0;text-align:center;color:rgba(255, 255, 255, 0.8);"> <b style="color:#fff">我想,左肩有你,右肩微笑</b> </div> <div style="line-height:1.38;margin:0.6rem 0;text-align:center;color:rgba(255, 255, 255, 0.8);"> <b style="color:#fff">我想,在你眼里,撒野奔跑</b> </div> <div style="line-height:1.38;margin:0.6rem 0;text-align:center;color:rgba(255, 255, 255, 0.8);"> <b style="color:#fff">我想,一个眼神,就到老 </b> </div> <div style="line-height:1.38;margin:0.6rem 0;text-align:center;color:rgba(255, 255, 255, 0.8);"> <b style="color:#fff">我想………        </b> </div></div><div class="author-info__bottom-group"><a class="author-info__bottom-group-left" href="/"><h1 class="author-info__name">伴随</h1><div class="author-info__desc">请保持那份热爱 奔赴下一场山海</div></a><div class="card-info-social-icons is-center"><a class="social-icon faa-parent animated-hover" href="https://qm.qq.com/q/1sv8urqpRS" target="_blank" title="QQ"><i class="anzhiyufont anzhiyu-icon-qq"></i></a></div></div></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-bullhorn anzhiyu-shake"></i><span>公告</span></div><div class="announcement_content"><div id="welcome-info"></div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-bars"></i><span>文章目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">生成一个随机日期</span></a></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">2.</span> <span class="toc-text">JAVA生成随机数API</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-java-util-Random"><span class="toc-number">2.1.</span> <span class="toc-text">1. java.util.Random</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-java-util-concurrent-ThreadLocalRandom"><span class="toc-number">2.2.</span> <span class="toc-text">2. java.util.concurrent.ThreadLocalRandom</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-java-security-SecureRandom"><span class="toc-number">2.3.</span> <span class="toc-text">3. java.security.SecureRandom</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-Math-random"><span class="toc-number">2.4.</span> <span class="toc-text">4. Math.random()</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-java-util-Random-ints-Java-8"><span class="toc-number">2.5.</span> <span class="toc-text">5. java.util.Random#ints (Java 8+)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">2.6.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%80%E5%90%8E%E5%86%8D%E8%AF%B4%E4%B8%80%E4%B8%8BHutool%E4%B8%AD%E7%9A%84%E9%9A%8F%E6%9C%BA%E6%95%B0API"><span class="toc-number">2.7.</span> <span class="toc-text">最后再说一下Hutool中的随机数API</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-history"></i><span>最近发布</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/8a0c.html" title="JAVA表达式解析器———EvalEx"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/11/tools3.png" onerror="this.onerror=null;this.src='https://up.ctext.top/default_bg.png'" alt="JAVA表达式解析器———EvalEx"/></a><div class="content"><a class="title" href="/8a0c.html" title="JAVA表达式解析器———EvalEx">JAVA表达式解析器———EvalEx</a><time datetime="2024-11-17T06:10:54.000Z" title="发表于 2024-11-17 14:10:54">2024-11-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/dfd4.html" title="IDEA快捷键大全"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/10/idea.png" onerror="this.onerror=null;this.src='https://up.ctext.top/default_bg.png'" alt="IDEA快捷键大全"/></a><div class="content"><a class="title" href="/dfd4.html" title="IDEA快捷键大全">IDEA快捷键大全</a><time datetime="2024-10-15T12:08:03.000Z" title="发表于 2024-10-15 20:08:03">2024-10-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/51a7.html" title="java随机数介绍以及生成随机日期"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/10/tools2.png" onerror="this.onerror=null;this.src='https://up.ctext.top/default_bg.png'" alt="java随机数介绍以及生成随机日期"/></a><div class="content"><a class="title" href="/51a7.html" title="java随机数介绍以及生成随机日期">java随机数介绍以及生成随机日期</a><time datetime="2024-10-14T12:16:33.000Z" title="发表于 2024-10-14 20:16:33">2024-10-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/3329.html" title="JAVA工具类(一)——生成班次排班记录"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/08/tools1.png" onerror="this.onerror=null;this.src='https://up.ctext.top/default_bg.png'" alt="JAVA工具类(一)——生成班次排班记录"/></a><div class="content"><a class="title" href="/3329.html" title="JAVA工具类(一)——生成班次排班记录">JAVA工具类(一)——生成班次排班记录</a><time datetime="2024-08-15T12:34:41.000Z" title="发表于 2024-08-15 20:34:41">2024-08-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/43a1.html" title="Feign调用者如何配置全局Header参数?"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/article/2024/08/feign.png" onerror="this.onerror=null;this.src='https://up.ctext.top/default_bg.png'" alt="Feign调用者如何配置全局Header参数?"/></a><div class="content"><a class="title" href="/43a1.html" title="Feign调用者如何配置全局Header参数?">Feign调用者如何配置全局Header参数?</a><time datetime="2024-08-12T11:39:34.000Z" title="发表于 2024-08-12 19:39:34">2024-08-12</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div id="workboard"><img class="workSituationImg boardsign" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/happy.svg" alt="下班了就该开开心心的玩耍,嘿嘿~" title="下班了就该开开心心的玩耍,嘿嘿~"/><div id="runtimeTextTip"></div></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" data-title="博客框架为Hexo_v7.2.0" title="博客框架为Hexo_v7.2.0"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/svg/hexo.svg" alt="博客框架为Hexo_v7.2.0"/></a><a class="github-badge" target="_blank" href="https://docs.anheyu.com/" style="margin-inline:5px" data-title="本站使用AnZhiYu主题" title="本站使用AnZhiYu主题"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/svg/anzhiyu.svg" alt="本站使用AnZhiYu主题"/></a><a class="github-badge" target="_blank" href="https://vercel.com/" style="margin-inline:5px" data-title="本站使用Vercel部署" title="本站使用Vercel部署"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/svg/vercel.svg" alt="本站使用Vercel部署"/></a><a class="github-badge" target="_blank" href="https://github.com/" style="margin-inline:5px" data-title="本站项目源码由Github托管" title="本站项目源码由Github托管"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/svg/github.svg" alt="本站项目源码由Github托管"/></a><a class="github-badge" target="_blank" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" style="margin-inline:5px" data-title="本站项目由又拍云提供CDN加速/云存储服务" title="本站项目由又拍云提供CDN加速/云存储服务"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/svg/up.svg" alt="本站项目由又拍云提供CDN加速/云存储服务"/></a><a class="github-badge" target="_blank" href="https://github.com/walinejs/waline" style="margin-inline:5px" data-title="本站评论系统使用Waline搭建" title="本站评论系统使用Waline搭建"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/svg/waline.svg" alt="本站评论系统使用Waline搭建"/></a></p></div><div id="footer-bar"><div class="footer-bar-links"><div class="footer-bar-left"><div id="footer-bar-tips"><div class="copyright">©2024 - 2025 By <a class="footer-bar-link" href="/" title="伴随" target="_blank">伴随</a></div></div><div id="footer-type-tips"></div><div class="js-pjax"><script>function subtitleType () {
getScript('https://yijuzhan.com/api/word.php?m=js').then(() => {
const con = str[0]
if (true) {
const from = '出自 ' + str[1]
const sub = []
sub.unshift(con, from)
window.typed = new Typed('#footer-type-tips', {
strings: sub,
startDelay: 300,
typeSpeed: 150,
loop: true,
backSpeed: 50,
})
} else {
document.getElementById('footer-type-tips').innerHTML = con
}
})
}
if (true) {
if (typeof Typed === 'function') {
subtitleType()
} else {
getScript('https://cdn.cbd.int/typed.js@2.1.0/dist/typed.umd.js').then(subtitleType)
}
} else {
subtitleType()
}
</script></div></div><div class="footer-bar-right"><a class="footer-bar-link" target="_blank" rel="noopener" href="https://beian.miit.gov.cn/" title="京ICP备2022017849号-2">京ICP备2022017849号-2</a></div></div></div></footer></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="sidebar-site-data site-data is-center"><a href="/archives/" title="archive"><div class="headline">文章</div><div class="length-num">23</div></a><a href="/tags/" title="tag"><div class="headline">标签</div><div class="length-num">21</div></a><a href="/categories/" title="category"><div class="headline">分类</div><div class="length-num">6</div></a></div><span class="sidebar-menu-item-title">功能</span><div class="sidebar-menu-item"><a class="darkmode_switchbutton menu-child" href="javascript:void(0);" title="显示模式"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i><span>显示模式</span></a></div><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">关于</div><div class="back-menu-list"><a class="back-menu-item" href="/about/" title="我"><img class="back-menu-item-icon" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/ico/orange.svg" alt="我"/><span class="back-menu-item-text">我</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">博客</div><div class="back-menu-list"><a class="back-menu-item" href="/album/" title="我的相册"><img class="back-menu-item-icon" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/ico/strawberry.svg" alt="我的相册"/><span class="back-menu-item-text">我的相册</span></a><a class="back-menu-item" href="/essay/" title="记录生活"><img class="back-menu-item-icon" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onerror="this.onerror=null,this.src="https://up.ctext.top/default_bg.png"" data-lazy-src="https://up.ctext.top/ico/apple.svg" alt="记录生活"/><span class="back-menu-item-text">记录生活</span></a></div></div></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 文章</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/"><i class="anzhiyufont anzhiyu-icon-grip-vertical faa-tada" style="font-size: 0.9em;"></i><span> 主页</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/archives/"><i class="anzhiyufont anzhiyu-icon-box-archive faa-tada" style="font-size: 0.9em;"></i><span> 总览</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><i class="anzhiyufont anzhiyu-icon-shapes faa-tada" style="font-size: 0.9em;"></i><span> 分类</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><i class="anzhiyufont anzhiyu-icon-tags faa-tada" style="font-size: 0.9em;"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 我的</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/growth.html"><i class="anzhiyufont anzhiyu-icon-heartbeat faa-tada" style="font-size: 0.9em;"></i><span> 博客岁月</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/music/"><i class="anzhiyufont anzhiyu-icon-music faa-tada" style="font-size: 0.9em;"></i><span> 音乐馆</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/"><i class="anzhiyufont anzhiyu-icon-images faa-tada" style="font-size: 0.9em;"></i><span> 相册集</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/essay/"><i class="anzhiyufont anzhiyu-icon-lightbulb faa-tada" style="font-size: 0.9em;"></i><span> 记录生活</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 小工具</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/air-conditioner/"><i class="anzhiyufont anzhiyu-icon-fan faa-tada" style="font-size: 0.9em;"></i><span> 小空调</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/gradation/"><i class="anzhiyufont anzhiyu-icon-envelope faa-tada" style="font-size: 0.9em;"></i><span> 渐变背景生成</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/9abe.html"><i class="anzhiyufont anzhiyu-icon-artstation faa-tada" style="font-size: 0.9em;"></i><span> tag-plugins文档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/nav"><i class="anzhiyufont anzhiyu-icon-link faa-tada" style="font-size: 0.9em;"></i><span> 网址导航</span></a></li><li><a class="site-page child faa-parent animated-hover" target="_blank" rel="noopener" href="https://map.ctext.top"><i class="anzhiyufont anzhiyu-icon-keyboard faa-tada" style="font-size: 0.9em;"></i><span> 飞车随机选图工具</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><span> 关于</span></a><ul class="menus_item_child"><li><a class="site-page child faa-parent animated-hover" href="/about/"><i class="anzhiyufont anzhiyu-icon-paper-plane faa-tada" style="font-size: 0.9em;"></i><span> 关于自己</span></a></li><li><a class="site-page child faa-parent animated-hover" href="javascript:toRandomPost()"><i class="anzhiyufont anzhiyu-icon-shoe-prints1 faa-tada" style="font-size: 0.9em;"></i><span> 随便逛逛</span></a></li></ul></div></div><span class="sidebar-menu-item-title">标签</span><div class="card-tags"><div class="item-headline"></div><div class="card-tag-cloud"><a href="/tags/Feign/" style="font-size: 0.88rem;">Feign<sup>1</sup></a><a href="/tags/IDEA/" style="font-size: 0.88rem;">IDEA<sup>1</sup></a><a href="/tags/JAVA/" style="font-size: 0.88rem;">JAVA<sup>5</sup></a><a href="/tags/Waline/" style="font-size: 0.88rem;">Waline<sup>1</sup></a><a href="/tags/docker/" style="font-size: 0.88rem;">docker<sup>1</sup></a><a href="/tags/hexo/" style="font-size: 0.88rem;">hexo<sup>4</sup></a><a href="/tags/java/" style="font-size: 0.88rem;">java<sup>1</sup></a><a href="/tags/linux/" style="font-size: 0.88rem;">linux<sup>2</sup></a><a href="/tags/logback/" style="font-size: 0.88rem;">logback<sup>1</sup></a><a href="/tags/nacos/" style="font-size: 0.88rem;">nacos<sup>1</sup></a><a href="/tags/window/" style="font-size: 0.88rem;">window<sup>1</sup></a><a href="/tags/%E4%BA%8C%E8%BF%9B%E5%88%B6/" style="font-size: 0.88rem;">二进制<sup>1</sup></a><a href="/tags/%E5%B7%A5%E5%85%B7%E7%B1%BB/" style="font-size: 0.88rem;">工具类<sup>3</sup></a><a href="/tags/%E5%BE%AE%E4%BF%A1/" style="font-size: 0.88rem;">微信<sup>1</sup></a><a href="/tags/%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/" style="font-size: 0.88rem;">排序算法<sup>1</sup></a><a href="/tags/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/" style="font-size: 0.88rem;">搜索引擎<sup>1</sup></a><a href="/tags/%E7%AC%A6%E5%8F%B7%E7%9A%84%E8%89%BA%E6%9C%AF/" style="font-size: 0.88rem;">符号的艺术<sup>1</sup></a><a href="/tags/%E8%84%9A%E6%9C%AC/" style="font-size: 0.88rem;">脚本<sup>2</sup></a><a href="/tags/%E8%BD%AF%E4%BB%B6%E8%AE%BE%E8%AE%A1%E5%B8%88/" style="font-size: 0.88rem;">软件设计师<sup>5</sup></a><a href="/tags/%E8%BD%AF%E8%80%83/" style="font-size: 0.88rem;">软考<sup>3</sup></a><a href="/tags/%E8%BE%BE%E6%A2%A6%E6%95%B0%E6%8D%AE%E5%BA%93/" style="font-size: 0.88rem;">达梦数据库<sup>1</sup></a></div></div><hr/></div></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="anzhiyufont anzhiyu-icon-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="anzhiyufont anzhiyu-icon-arrows-left-right"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="anzhiyufont anzhiyu-icon-gear"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="anzhiyufont anzhiyu-icon-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="anzhiyufont anzhiyu-icon-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i></button></div></div><div id="nav-music"><a id="nav-music-hoverTips" onclick="anzhiyu.musicToggle()" accesskey="m">播放音乐</a><div id="console-music-bg"></div><meting-js id="2788494248" server="netease" type="playlist" mutex="true" preload="none" theme="var(--anzhiyu-main)" data-lrctype="0" order="random" volume="0.7"></meting-js></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="anzhiyufont anzhiyu-icon-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="anzhiyufont anzhiyu-icon-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="anzhiyufont anzhiyu-icon-arrow-rotate-right" style="font-size: 1rem;"></i></div><div class="rightMenu-item" id="menu-top"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i></div></div><div class="rightMenu-group rightMenu-line rightMenuPlugin"><div class="rightMenu-item" id="menu-copytext"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制选中文本</span></div><div class="rightMenu-item" id="menu-pastetext"><i class="anzhiyufont anzhiyu-icon-paste"></i><span>粘贴文本</span></div><a class="rightMenu-item" id="menu-commenttext"><i class="anzhiyufont anzhiyu-icon-comment-medical"></i><span>引用到评论</span></a><div class="rightMenu-item" id="menu-newwindow"><i class="anzhiyufont anzhiyu-icon-window-restore"></i><span>新窗口打开</span></div><div class="rightMenu-item" id="menu-copylink"><i class="anzhiyufont anzhiyu-icon-link"></i><span>复制链接地址</span></div><div class="rightMenu-item" id="menu-copyimg"><i class="anzhiyufont anzhiyu-icon-images"></i><span>复制此图片</span></div><div class="rightMenu-item" id="menu-downloadimg"><i class="anzhiyufont anzhiyu-icon-download"></i><span>下载此图片</span></div><div class="rightMenu-item" id="menu-newwindowimg"><i class="anzhiyufont anzhiyu-icon-window-restore"></i><span>新窗口打开图片</span></div><div class="rightMenu-item" id="menu-search"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i><span>站内搜索</span></div><div class="rightMenu-item" id="menu-searchBaidu"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i><span>百度搜索</span></div><div class="rightMenu-item" id="menu-music-toggle"><i class="anzhiyufont anzhiyu-icon-play"></i><span>播放音乐</span></div><div class="rightMenu-item" id="menu-music-back"><i class="anzhiyufont anzhiyu-icon-backward"></i><span>切换到上一首</span></div><div class="rightMenu-item" id="menu-music-forward"><i class="anzhiyufont anzhiyu-icon-forward"></i><span>切换到下一首</span></div><div class="rightMenu-item" id="menu-music-playlist" onclick="window.open("https://music.163.com/#/playlist?id=2788494248", "_blank");" style="display: none;"><i class="anzhiyufont anzhiyu-icon-radio"></i><span>查看所有歌曲</span></div><div class="rightMenu-item" id="menu-music-copyMusicName"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制歌名</span></div></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" id="menu-randomPost"><i class="anzhiyufont anzhiyu-icon-shuffle"></i><span>随便逛逛</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="anzhiyufont anzhiyu-icon-cube"></i><span>博客分类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="anzhiyufont anzhiyu-icon-tags"></i><span>文章标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item" id="menu-copy" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制地址</span></a><a class="rightMenu-item" id="menu-commentBarrage" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-message"></i><span class="menu-commentBarrage-text">关闭热评</span></a><a class="rightMenu-item" id="menu-darkmode" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i><span class="menu-darkmode-text">深色模式</span></a><a class="rightMenu-item" id="menu-translate" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-language"></i><span>轉為繁體</span></a></div></div><div id="rightmenu-mask"></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.cbd.int/@fancyapps/ui@5.0.28/dist/fancybox/fancybox.umd.js"></script><script src="https://cdn.cbd.int/instant.page@5.2.0/instantpage.js" type="module"></script><script src="https://cdn.cbd.int/vanilla-lazyload@17.8.5/dist/lazyload.iife.min.js"></script><script src="https://cdn.cbd.int/node-snackbar@0.1.16/dist/snackbar.min.js"></script><script>function panguFn () {
if (typeof pangu === 'object') pangu.autoSpacingPage()
else {
getScript('https://cdn.cbd.int/pangu@4.0.7/dist/browser/pangu.min.js')
.then(() => {
pangu.autoSpacingPage()
})
}
}
function panguInit () {
if (false){
GLOBAL_CONFIG_SITE.isPost && panguFn()
} else {
panguFn()
}
}
document.addEventListener('DOMContentLoaded', panguInit)</script><canvas id="universe"></canvas><script async src="https://npm.elemecdn.com/anzhiyu-theme-static@1.0.0/dark/dark.js"></script><script async src="/anzhiyu/random.js"></script><script async="async">(function () {
var grt = new Date("01/02/2024 00:00:00"); //设置网站上线时间
var now = new Date();
var dnum;
var hnum;
var mnum;
var snum;
var nowHour;
// 计算并更新天数、小时数、分钟数和秒数
function updateTime() {
now = new Date(); // 更新 now 的值
nowHour = now.getHours(); // 更新 nowHour 的值
var days = (now - grt) / 1000 / 60 / 60 / 24;
dnum = Math.floor(days);
var hours = (now - grt) / 1000 / 60 / 60 - 24 * dnum;
hnum = Math.floor(hours);
if (String(hnum).length == 1) {
hnum = "0" + hnum;
}
var minutes = (now - grt) / 1000 / 60 - 24 * 60 * dnum - 60 * hnum;
mnum = Math.floor(minutes);
if (String(mnum).length == 1) {
mnum = "0" + mnum;
}
var seconds = (now - grt) / 1000 - 24 * 60 * 60 * dnum - 60 * 60 * hnum - 60 * mnum;
snum = Math.round(seconds);
if (String(snum).length == 1) {
snum = "0" + snum;
}
}
// 更新网页中显示的网站运行时间
function updateHtml() {
const footer = document.getElementById("footer");
if (!footer) return
let currentTimeHtml = "";
if (nowHour < 18 && nowHour >= 9) {
// 如果是上班时间,默认就是"安知鱼-上班摸鱼中.svg"图片,不需要更改
currentTimeHtml = `本站居然运行了 ${dnum} 天<span id='runtime'> ${hnum} 小时 ${mnum} 分 ${snum} 秒 </span><i class='anzhiyufont anzhiyu-icon-heartbeat' style='color:red'></i>`;
} else {
// 如果是下班时间,插入"安知鱼-下班啦.svg"图片
let img = document.querySelector("#workboard .workSituationImg");
if (img != null) {
img.src = "https://up.ctext.top/happy.svg";
img.title = "下班了就该开开心心的玩耍,嘿嘿~";
img.alt = "下班了就该开开心心的玩耍,嘿嘿~";
}
currentTimeHtml = `本站居然运行了 ${dnum} 天<span id='runtime'> ${hnum} 小时 ${mnum} 分 ${snum} 秒 </span><i class='anzhiyufont anzhiyu-icon-heartbeat' style='color:red'></i>`;
}
if (document.getElementById("runtimeTextTip")) {
document.getElementById("runtimeTextTip").innerHTML = currentTimeHtml;
}
}
setInterval(() => {
updateTime();
updateHtml();
}, 1000);
})();</script><div class="js-pjax"><script>(() => {
const locale = {
nick: '你的专属昵称',
nickError: '昵称太短啦!至少得有3个字符才能算数哦!',
mail: '你的电子小信箱',
mailError: '哎呀,这不是一个合格的邮箱地址哦,请再检查一遍!',
link: '你有个酷酷的网址吗?',
optional: '这个嘛,想填就填,不填也行!',
placeholder: '吐槽一下?',
sofa: '来,坐沙发上,发表你的评论吧!',
submit: '一键发送,让世界听到你的声音!',
like: '点个赞,让TA知道你的心意!',
cancelLike: '哎呀,不小心点错了,取消赞!',
reply: '回复TA,开启一场对话吧!',
cancelReply: '等等,我话还没说完,取消回复!',
comment: '来,说说你的看法,让评论区热闹起来!',
refresh: '刷新一下,看看有啥新动态!',
more: '哇塞,还有更多精彩内容等你来加载!',
preview: '先睹为快,预览一下你的大作吧!',
emoji: '来,加点表情,让你的评论更生动!',
uploadImage: '上传你的美照,让大家一起欣赏!',
seconds: '刚刚才发的,新鲜出炉!',
minutes: '几分钟前,还热乎着呢!',
hours: '几小时前,热度还在哦!',
days: '几天前,但依旧值得一看!',
now: '哇塞,刚刚发的,快抢沙发!',
uploading: '稍等片刻,你的图片正在飞奔而来!',
login: '登录一下,解锁更多功能!',
logout: '拜拜了您嘞,下次再见!',
admin: '博主大人在此,谁敢造次!',
sticky: '置顶一下,让更多人看到你的精彩内容!',
word: '字',
wordHint: '评论字数要在0到1字之间哦!\n现在你已经写了$2个字了,加油!',
anonymous: '神秘人出没,猜猜是谁?',
level0: '潜水员,深藏不露!',
level1: '冒泡小能手,偶尔露个头!',
level2: '吐槽大师,一针见血!',
level3: '活跃分子,无处不在!',
level4: '话痨达人,说个不停!',
level5: '传说级大神,膜拜一下!',
gif: '动态表情包,让你的评论更有趣!',
gifSearchPlaceholder: '快来搜索你喜欢的表情包,让评论更生动!',
profile: '看看我的个人资料,了解一下我吧!',
approved: '审核通过,可以展示啦!',
waiting: '正在等待审核,别急哦!',
spam: '垃圾内容,走开走开!',
unsticky: '换个位置看看!',
oldest: '看看最早的评论!',
latest: '看看最新的动态!',
hottest: '看看哪条评论最火!',
reactionTitle: '快来对这篇文章发表你的看法吧,让博主知道你的想法!😜'
};
const initWaline = () => {
const waline = Waline.init(Object.assign({
el: '#waline-wrap',
serverURL: 'https://bc.ctext.top/',
pageview: false,
dark: 'html[data-theme="dark"]',
path: window.location.pathname,
turnstileKey: '0x4AAAAAAAexA2vW2PBFT3wv',
comment: false,
copyright: false,
reaction: true,
locale
}, null))
}
const loadWaline = async () => {
if (typeof Waline === 'object') initWaline()
else {
await getCSS('https://cdn.cbd.int/@waline/client@3.1.3/dist/waline.css')
await getScript('https://cdn.cbd.int/@waline/client@3.1.3/dist/waline.js')
initWaline()
}
}
if ('Waline' === 'Waline' || !true) {
if (true) anzhiyu.loadComment(document.getElementById('waline-wrap'),loadWaline)
else setTimeout(loadWaline, 0)
} else {
window.loadOtherComment = loadWaline
}
})()</script><input type="hidden" name="page-type" id="page-type" value="post"></div><script>window.addEventListener('load', () => {
const changeContent = content => {
if (content === '') return content
content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[图片]') // replace image link
content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
content = content.replace(/<pre><code>.*?<\/pre>/gi, '[代码]') // replace code
content = content.replace(/<[^>]+>/g,"") // remove html tag
if (content.length > 150) {
content = content.substring(0,150) + '...'
}
return content
}
const generateHtml = array => {
let result = ''
if (array.length) {
for (let i = 0; i < array.length; i++) {
result += '<div class=\'aside-list-item\'>'
if (true) {
const name = 'data-lazy-src'
result += `<a href='${array[i].url}' class='thumbnail'><img ${name}='${array[i].avatar}' alt='${array[i].nick}'></a>`
}
result += `<div class='content'>
<a class='comment' href='${array[i].url}' title='${array[i].content}'>${array[i].content}</a>
<div class='name'><span>${array[i].nick} / </span><time datetime="${array[i].date}">${anzhiyu.diffDate(array[i].date, true)}</time></div>
</div></div>`
}
} else {
result += '没有评论'
}
let $dom = document.querySelector('#card-newest-comments .aside-list')
$dom && ($dom.innerHTML= result)
window.lazyLoadInstance && window.lazyLoadInstance.update()
window.pjax && window.pjax.refresh($dom)
}
const getComment = async () => {
try {
const res = await fetch('https://bc.ctext.top/api/comment?type=recent&count=6', { method: 'GET' })
const result = await res.json()
const walineArray = result.data.map(e => {
return {
'content': changeContent(e.comment),
'avatar': e.avatar,
'nick': e.nick,
'url': e.url + '#' + e.objectId,
'date': e.time || e.insertedAt
}
})
saveToLocal.set('waline-newest-comments', JSON.stringify(walineArray), 10/(60*24))
generateHtml(walineArray)
} catch (err) {
console.error(err)
const $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.textContent= "无法获取评论,请确认相关配置是否正确"
}
}
const newestCommentInit = () => {
if (document.querySelector('#card-newest-comments .aside-list')) {
const data = saveToLocal.get('waline-newest-comments')
if (data) {
generateHtml(JSON.parse(data))
} else {
getComment()
}
}
}
newestCommentInit()
document.addEventListener('pjax:complete', newestCommentInit)
})</script><script async data-pjax src="https://cdn.cbd.int/anzhiyu-theme-static@1.0.0/waterfall/waterfall.js"></script><script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/qrcodejs/1.0.0/qrcode.min.js"></script><script src="/js/anzhiyu/right_click_menu.js"></script><link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-theme-static@1.1.9/icon/ali_iconfont_css.css"><script async src="https://at.alicdn.com/t/c/font_4489064_ow7l1rcvcw.js?spm=a313x.manage_type_myprojects.i1.12.61783a81xP1PqH&file=font_4489064_ow7l1rcvcw.js"></script><script async data-pjax src="/js/imgloaded.js?1"></script><script src="https://cdn.staticfile.org/jquery/3.6.3/jquery.min.js"></script><script defer="true" src="/js/welcome.js"></script><script defer="true" src="/js/hideRolling.js"></script><script defer="true" src="/js/countdown.js"></script><script defer src="https://cdn.jsdelivr.net/combine/npm/jquery@latest/dist/jquery.min.js,gh/weilining/jsdelivr/jquery/circlemagic/circlemagic.min.js,gh/weilining/jsdelivr@latest/jquery/circlemagic/butterflycirclemagic.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.cbd.int/butterfly-extsrc@1.1.3/dist/canvas-nest.min.js"></script><script id="click-heart" src="https://cdn.cbd.int/butterfly-extsrc@1.1.3/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-theme-static@1.0.0/aplayer/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.cbd.int/anzhiyu-blog-static@1.0.1/js/APlayer.min.js"></script><script src="https://cdn.cbd.int/hexo-anzhiyu-music@1.0.1/assets/js/Meting2.min.js"></script><script src="https://cdn.cbd.int/pjax@0.2.8/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]
var pjax = new Pjax({
elements: 'a:not([target="_blank"])',
selectors: pjaxSelectors,
cacheBust: false,
analytics: false,
scrollRestoration: false
})
document.addEventListener('pjax:send', function () {
// removeEventListener scroll
anzhiyu.removeGlobalFnEvent('pjax')
anzhiyu.removeGlobalFnEvent('themeChange')
document.getElementById('rightside').classList.remove('rightside-show')
if (window.aplayers) {
for (let i = 0; i < window.aplayers.length; i++) {
if (!window.aplayers[i].options.fixed) {
window.aplayers[i].destroy()
}
}
}
typeof typed === 'object' && typed.destroy()
//reset readmode
const $bodyClassList = document.body.classList
$bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')
})
document.addEventListener('pjax:complete', function () {
window.refreshFn()
document.querySelectorAll('script[data-pjax]').forEach(item => {
const newScript = document.createElement('script')
const content = item.text || item.textContent || item.innerHTML || ""
Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
newScript.appendChild(document.createTextNode(content))
item.parentNode.replaceChild(newScript, item)
})
GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()
typeof panguInit === 'function' && panguInit()
// google analytics
typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});
// baidu analytics
typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);
typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()
// prismjs
typeof Prism === 'object' && Prism.highlightAll()
})
document.addEventListener('pjax:error', e => {
if (e.request.status === 404) {
pjax.loadUrl('/404.html')
}
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><script charset="UTF-8" src="https://cdn.cbd.int/anzhiyu-theme-static@1.1.5/accesskey/accesskey.js"></script></div><div id="popup-window"><div class="popup-window-title">通知</div><div class="popup-window-divider"></div><div class="popup-window-content"><div class="popup-tip">你好呀</div><div class="popup-link"><i class="anzhiyufont anzhiyu-icon-arrow-circle-right"></i></div></div></div><!-- hexo injector body_end start --><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script><!-- hexo injector body_end end --></body></html>