Click to See Complete Forum and Search --> : generating numbers


rontooo
03-23-2003, 06:07 AM
I have a web site I want to start selling products at. The site is entirely HTML with no use of any coding functionality other than JS. So far I'm planning to use Mals ecommerece site for the shopping cart aspect of it.

http://www.mals-e.com

To use this site I need to generate a unique "userid". Is using the Math.random() in JS the real only solution? Given the fact I only have JS capabilities at my disposal? My plan (so far) was to generate a number using random() and then set that value in a cookie for persistance or "session" purposes. Is this the best approach? The only approach?

Here's the code I was thinking of using...

function createUserID() {
var myNum = 0;
var myMax = 1000000;
do {
myNum = Math.floor(Math.random() * myMax);
alert(myNum);
} while(myNum < 100000 || myNum >= 1000000);
return myNum;
}

rontooo
03-23-2003, 03:50 PM
could I not generate a number when a user hits the home page, write a cookie storing that value and then retrieve it when I need it?

dabush
03-23-2003, 04:01 PM
you could, but as Dave said, this is not the best way of going about it. But, if you only hava javascript, then i guess that will have to do