472,796 Members | 1,928 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 software developers and data experts.

how to create guid by javascript?


we need create a GUID in web page, just like:
{26C2E7C8-C689-D1D5-C452-58EC5A2F2A39}

Could anyone tell me how to use javascript
to create it without ActiveX object?
Aug 14 '06 #1
7 32720
The following gives a description of the algorithm:
http://www.webdav.org/specs/draft-le...s-guids-01.txt

tamsun написа:
we need create a GUID in web page, just like:
{26C2E7C8-C689-D1D5-C452-58EC5A2F2A39}

Could anyone tell me how to use javascript
to create it without ActiveX object?
Aug 14 '06 #2
JRS: In article <ht********************************@4ax.com>, dated
Mon, 14 Aug 2006 15:36:48 remote, seen in news:comp.lang.javascript,
tamsun <ta****@gmail.composted :
>
we need create a GUID in web page, just like:
{26C2E7C8-C689-D1D5-C452-58EC5A2F2A39}

Could anyone tell me how to use javascript
to create it without ActiveX object?
To make a random string of that form, you can note that it is made up of
four-hex-character units.

function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).subst ring(1) }

should generate such a unit of random value;

Ans =
(S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()).toUpperCase()

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 14 '06 #3
Thank you very much.
On 14 Aug 2006 01:17:50 -0700, "Georgi Naumov" <go******@gmail.com>
wrote:
>The following gives a description of the algorithm:
http://www.webdav.org/specs/draft-le...s-guids-01.txt
Aug 15 '06 #4
Great, It's a good method. thank you very much.
I wonder can this method ensure I can create the unique string ?
I don't know the random mechanism of javascript,
e.g. I have 300 computers, and create this random
string concurring, javascript can ensure the
random string is unique?

On Mon, 14 Aug 2006 21:43:39 +0100, Dr John Stockton
<jr*@merlyn.demon.co.ukwrote:
>JRS: In article <ht********************************@4ax.com>, dated
Mon, 14 Aug 2006 15:36:48 remote, seen in news:comp.lang.javascript,
tamsun <ta****@gmail.composted :
>>
we need create a GUID in web page, just like:
{26C2E7C8-C689-D1D5-C452-58EC5A2F2A39}

Could anyone tell me how to use javascript
to create it without ActiveX object?

To make a random string of that form, you can note that it is made up of
four-hex-character units.

function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).subst ring(1) }

should generate such a unit of random value;

Ans =
(S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()).toUpperCase()
Aug 16 '06 #5
tamsun wrote on 16 aug 2006 in comp.lang.javascript:
and create this random
string concurring, javascript can ensure the
random string is unique?
Uniqueness does not exist in an limited string.
is 1 in a million enough for you?
[changed the string function to:
Math.random().toString(16).substring(2)]
<script type='text/javascript'>

var a,b,n=1;

a = Math.random().toString(16).substring(2);

while (a!=b && n<1e6) {
b=a;
a = Math.random().toString(16).substring(2);
n++;
};

document.write(a+' (value)<br>');
document.write(n+' (number of strings tested)<br>');

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 16 '06 #6
On 16/08/2006 02:46, tamsun wrote:

[snip]
e.g. I have 300 computers, and create this random
string concurring, javascript can ensure the
random string is unique?
No. To guarantee that, make a central authority (a single designated
machine) responsible for creating and tracking the generated identifiers.

Mike
When replying to this group, please refrain from top-posting.
Aug 16 '06 #7
JRS: In article <lr********************************@4ax.com>, dated
Wed, 16 Aug 2006 09:46:13 remote, seen in news:comp.lang.javascript,
tamsun <ta****@gmail.composted :
>Great, It's a good method. thank you very much.
I wonder can this method ensure I can create the unique string ?
I don't know the random mechanism of javascript,
e.g. I have 300 computers, and create this random
string concurring, javascript can ensure the
random string is unique?

On Mon, 14 Aug 2006 21:43:39 +0100, Dr John Stockton
<jr*@merlyn.demon.co.ukwrote:
Please read the newsgroup FAQ on proper article formatting.

Only collective management can ensure uniqueness.

Indeed, if your 300 computers are identical, and the function
Math.random() is called at the same time (on some definition of time) on
all of them, then you probably should get identical results on all 300.

(The method of initialisation of the Random Number Generator is
unspecified, but it is common to use clock time; time from some other
origin could be used. Note that the resolution of the initialisation
may be less than that of the generator - see for example <URL:http://www
..merlyn.demon.co.uk/pas-rand.htm>.)

One can test the RNG to see its resolution : "Generator Properties" in
<URL:http://www.merlyn.demon.co.uk/js-randm.htm>.

It seems that some browsers have a 32-bit resolution, others at least
53-bit, in the RNG.

The question of probability of uniqueness is like that of the well-known
birthdays question; pick 23 people at random, and probably two or more
will have the same birthday.

With a 32-bit generator, ISTM that your chances of non-uniqueness are of
the order of 1 in (4E9/300^2) which is about 50000 - you will have to
decide whether that would be good enough, remembering Murphy.

Note : Evertjan's test does what it should; but, as Math.random() can
give exactly 0.5, it cannot be used as a direct substitute for mine.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 16 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert Oschler | last post by:
Anybody seen a Javascript function that would generate a fairly robust equivalent to the Windows GUID (Globally Unique Identifier)? thx Robert Oschler "Let the web hear you, add your...
1
by: Alexander Muylaert | last post by:
Hi How can I generate a Guid in sourcecode? In delphi I Have shift-ctrl-g. This inserts a guid as text inside my source. How can I have visual studio generate a guid? kind regards
0
by: Joe Finsterwald | last post by:
Recently I needed to add a confirm to a LinkButton that called a JavaScript function on success, and did nothing on failure. I found documentation on adding a confirm, but not on how to place a...
1
by: Grey | last post by:
how to create a GUID from ASP.NET??? Is it possible to use this ID as primary key in createing DB record?? Million Thanks..
1
by: Axel Dahmen | last post by:
Hi, I can't create local fragment hyperlinks or JavaScript hyperlinks in ASP.NET. It always appends the current path to any value. How can I switch that off? Examples: * ...
9
by: Mis Dep. | last post by:
Dear all What is Create GUID on menu Tools in vb.net and how can i use it for something . as exsample Brg, TingN@ng
1
by: philmaz | last post by:
What I am trying to do is create a form that people can use to enter their email address to sign up for a mailing list. Once they enter their email address, I want the script to open up a txt file...
6
by: davibugi | last post by:
Hi people please help me out with this code cant find any person who has done it before. I want my calculations to be done without posting to another page. On change on the entered amount the...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.