LoginSignup

Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

JavascriptでUUID4を取得する

Last updated at Posted at 2024-06-19
function uuid4(){
	return [...new Array(36)].map((_,i) => {
		switch(i){
			case 8:
			case 13:
			case 18:
			case 23:
				return '-';
			case 14:
				return '4';
			case 19:
				return parseInt(Math.random() * 4 + 8, 10).toString(16);
			default:
				return parseInt(Math.random() * 16).toString(16);
		}
	}).join("");
}

自分用メモ。

"RRRRRRRR-RRRR-4RRR-rRRR-RRRRRRRRRRRR".replaceAll(/R/g,()=>parseInt(Math.random()*16).toString(16)).replaceAll(/r/g,()=>parseInt(Math.random()*4+8).toString(16))

単行実装ならこっち。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
brnakina

@brnakina

仕事でWebシステム開発やってます。 PHP、MySQL、Javascriptあたりが好きです。

Comments

ss8826
@ss8826
"RRRRRRRR-RRRR-4RRR-rRRR-RRRRRRRRRRRR".replaceAll(/R/g,()=>parseInt(Math.random()*16).toString(16)).replaceAll(/r/g,()=>parseInt(Math.random()*4+8).toString(16))

単行実装ならこっち。

私はこうしてます。

'00000000-0000-4000-1000-000000000000'.replace(/0|1/g,m=>(Math.random()*[16,4][m]|[0,8][m]).toString(16));
1

Let's comment your feelings that are more than good

Being held Article posting campaign

生成AIに関する記事を書こう!

~
View details

そうだ!TestRailを使ってみよう!!

~
View details
0
0

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address