473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Cleanest way to create a RANDOM, UNREPEAT-ABLE Long value???

I want to periodically generate a completely new random Long value in
some code I'm writing.

The value need not be based on anything in particular, I just need to
know that if I have to generate another Long value at another time
that it is extrememly unlikely that I will generate the same Long
value that I have created before.

I assume I will need to use the 'Random' function for this. I'm
writing to ask for some feedback as to the 'cleanest/most efficient'
code for creating this random-unrepeatable value.

Thanks in advance for any feedback you'd care to share.
Dec 11 '07 #1
1 1673


"Alan Mailer" wrote:
I want to periodically generate a completely new random Long value in
some code I'm writing.

The value need not be based on anything in particular, I just need to
know that if I have to generate another Long value at another time
that it is extrememly unlikely that I will generate the same Long
value that I have created before.

I assume I will need to use the 'Random' function for this. I'm
writing to ask for some feedback as to the 'cleanest/most efficient'
code for creating this random-unrepeatable value.

Thanks in advance for any feedback you'd care to share.
Random and unrepeatable are contradictory. Is there a reason it really
needs to be random?

If you want unique and pseudo-random, then you want to look at
Random.NextBytes() and probably ByteConverter.ConvertTo(). This can give you
four bytes from which to construct a long value. You basically need to
construct a running list<longwith the numbers used previously (or a
database) and check each new entry for previous use.

Dec 13 '07 #2

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

Similar topics

2
by: Daniel Lidström | last post by:
Hi, I would like to know the cleanest way to change the serialization of my Line class from: <Line staStart="2327.02" length="10.00000003390744"> <End>549016.570965 57945.741122</End>...
2
by: Zeb Davis | last post by:
Hello Newsgroup I'm new in C#, and I was wanting to create a console application involving generating 100 random numbers between 0 and 1000. After running that method, I want to write a method...
0
by: | last post by:
ASP.NET 2.0 simplifies binding datasources to controls like the repeater. These new methods allow nearly code-less mechanisms to dump data to a page. I like this new feature a whole lot. HTML...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
4
by: | last post by:
I'm finishing an .ascx control that takes custom properties. I've made a generalized administrative form that can be made specific by calling the user control with a bunch of parameters (e.g. ...
11
by: John Henry | last post by:
Hi list, I am sure there are many ways of doing comparision but I like to see what you would do if you have 2 dictionary sets (containing lots of data - like 20000 keys and each key contains a...
7
by: tamsun | last post by:
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?
9
by: twang090 | last post by:
Trying to create a 12 digit "guid", but have no idea on how to, anyone please have any thought? Thanks in advance.
1
by: thaond | last post by:
Hi ! I want to create a Random number be in the Around, but not same the numbers created before ! Exam : My around : 0000,......,9999 Random number was created : 1234, 2134, 0001, 9998...
13
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I am not accustomed to creating xml files programmatically. The big picture is this: This will be in VB/VS 2005/ winforms. I have a DTD, a sample XML, and an outside data source I will use to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.