|
I need to write an article, this gets asked so often.
You create a list of numbers, which is the range of numbers you want to choose from ( such as 1-100 ).
You generate a random number between 0 and 99 ( for example ). You pull the number at that index out, and remove it from the list. Next time, you generate a number between 0 and 98, and do the same. And so on.
The other option is to write a custom sorting routine that returns a random number, but I've never tried that, I'm not sure if it wouldn't end up going for ever as the sort order keeps changing.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: You create a list of numbers, which is the range of numbers you want to choose from ( such as 1-100 ). You generate a random number between 0 and 99 ( for example ). You pull the number at that index out, and remove it from the list. Next time, you generate a number between 0 and 98, and do the same. And so on.
Hey, Christian, your technique works very well if the sample size is small and many of those numbers will be used (for instance, you want 15 unique random numbers less than 25).
If the sample size is large ( 0 - 10 million ) and very few of them will be used, you are better off generating numbers within the range and checking if they have already been generated (you have to maintain a list for that). If not, you add the number to the list and use it.
Cheers,
Vikram.
Zeppelin's law: In any Soapbox discussion involving Stan Shannon, the probability of the term "leftist" or "Marxist" appearing approaches 1 monotonically.
Harris' addendum: I think you meant "monotonously".
Martin's second addendum: Jeffersonian... I think that should at least get a mention.
|
|
|
|
|
how many teachers are going to get their students to run this code on a sample size that large though
|
|
|
|
|
Yes, that's probably true, I can't imagine needing a small number of unique values between 1 and 10 million, tho. I guess it's possible, and what you say is a good point.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
I have this problem that requires different areas (30x40, 10x40) of radio buttons.
How can I do this on the fly? I can't figure out how can I create the radio buttons and add them to the panel using a for loop? I want to name the radio buttons rb_1_1, rb_1_2 or rb11, rb12, etc.
I know I have to create the radio button objects -> RadioButton rb_1_1 = new RadioButton()
but how would I change the rb_1_1 when it loops again?
Thanks.
Desmond
|
|
|
|
|
|
Sorry Gareth, that's not want I wanted.
I know I can do it that way but what if I have 1000 radio buttons I want to create,
RadioButton rb_1_1 = new RadioButton();
RadioButton rb_1_2 = new RadioButton();
and so on
for 1000 times.
Is there a way to do it programmatically, so that I can just create a for loop and it creates the radio buttons for me?
And I need to do this in windows not ASP.net (I can do it in ASP.net).
Thanks.
Desmond
|
|
|
|
|
Desmond Lim,
Just do:
for (int i = 0; i < 1000; i++)
{
}
Why do you want to create 1000 radio buttons? Can you give a bit more info on what your trying to do because there might be a better way around it.
Regards,
Gareth.
|
|
|
|
|
I'm creating a software that allows the user to enter data for research purposes.
The slide/grid they use comes in different sizes, 20x30, 40x40, 100x30, etc. They want to be able to choose the size (by list box) and when a particular size is chosen, the grid of radio buttons corresponding to the size that they want will be created i.e. if they choose 20x30, 20 columns by 30 rows of radio buttons will be created.
The radio buttons will then be use to enter the data that corresponds to that part of the grid, that is to say, when the user clicks the Col 2 and Row 3 radio button, a window might pop up with the information needed for that part. Which means that each individual radio button has to be identifiable.
So back to my question how do you do a create radio button with different IDs because I know that when you do a
RadioButton rb01 = new RadioButton(); it creates the radio button object, I just don't know how to create radio buttons that have different IDs, i.e. rb01, rb02, rb03, etc. via using a loop. I know that if I do something like
for (int i = 0; i < 1000; i++)<br />
{<br />
RadioButton rbNew = new RadioButton();<br />
(move rbNew to a particular x y coordinate);<br />
rbNew.name = "rb01";<br />
}
This doesn't seem to work for I only get 1 radio button.
If you can think another way to do this, I'll really appreciate it.
Thanks.
Desmond
|
|
|
|
|
Desmond Lim,
rbNew.name = "rb" + i.ToString();
Regards,
Gareth.
|
|
|
|
|
hello every body
DO some one have any idea about how to prevent a specific file to be downloaded when i try to download something from the internet.
For example suppose that file name is: Somme.Cs
so when i try to download any kind of package and this package contain the current file name so the download should be stopped.
best regard
dghdfghdfghdfghdgh
|
|
|
|
|
Not possible. An anti virus program could monitor the file system and check files as they come down, and if they can be read, they can be examined for that file and deleted. When I click on 'myfiles.msi', IE has no idea if a specific file is inside that msi, how could it ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
but it can be detected if i have only this file name to download not a package?
if yes plz tell me how can i do this
best regards
dghdfghdfghdfghdgh
|
|
|
|
|
I guess it depends on the context. Do you mean stop any browser from downloading a specific file ? You'd need a plug in for IE and I'm not sure how you'd do it for Firefox, or if it would be possible. Do you mean a browser that's a control in your app ? That would be a lot easier.
I know if I put an IE control in a form, then any IE instance that operates, causes events to fire in my code. For IE, it may be as simple as putting up a form with IE in it and through that, getting events for all browser instances.
Still sounds stupid to me. You want to block a file with a specific name from being downloaded. I think it's clear how easy this would be to defeat, what's the point ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
in ohter words,
i want to create a program or a service and install it in the ISP provider.So when client try to download a non illegal file the ISP prevent the download action.
thanks
dghdfghdfghdfghdgh
|
|
|
|
|
Oh - you never asked this. You want to write something on the ISP end, not on the user end ? That's a lot more doable, for all sorts of reasons, not least, the fact that you can install any program you want there.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
ellllllllie wrote: DO some one have any idea about how to prevent a specific file to be downloaded when i try to download something from the internet.
For example suppose that file name is: Somme.Cs
You would normally limit access to the files using an HttpForbiddenHandler. You add the extensions you want blocking into the httpHandlers section of your local web.config file
:<system.web>
<httpHandlers>
<add verb="*" path="*.cs" type="System.Web.HttpForbiddenHandler" />
</httpHandlers>
</system.web>
|
|
|
|
|
Notice that any file within your web application can be downloaded. A webapplication starts from the root folder and all subfolders where no other application is running.
To prevent certain files to be downloaded you should place them outside your web-application and send them to the visitor when 'access is granted'
for example, your web application is running in :
e:\inetpub\wwwroot\yourwebsite\
All files and folders from e:\inetpub\wwwroot\yourwebsite\ and lower are readable for users (ofcourse depends on folder permissions etc etc, but by default readable)
When you place your files for example in a folder e:\inetpub\wwwroot\upload\ and create a aspx file (for example 'download.aspx') in your website which has access to the e:\inetpub\wwwroot\upload\ path you can make those files available to users. Then you can check in download.aspx wether a visitor is allowed to download the file or not. If not, you show a message like access denied, if so you open the file and send the content to the user.
Don't know if my story is clear, but hope you understand what I mean
|
|
|
|
|
Eduard Keilholz wrote: Notice that any file within your web application can be downloaded.
This isn't true in a properly configured site. If it was true, then this would represent a serious security breach in ASP.NET. Here's a test - try to download the web.config file from an ASP.NET site - you can't do it because the machine.config maps this to an HttpForbiddenHandler.
|
|
|
|
|
Erhm, I didn't think of the HttpForbiddenHandler which may be a better solution, but I don't agree my solution isn't true. If you have a folder on your server having sufficient permissions, you're web application is able to read or (depending on those permissions) even write there.
That way you make file available through a WebForm and not via a direct URL.
Or am I thinking seriously stupid
|
|
|
|
|
You are right that an application could transmit the content back out as a serialized byte stream from any folder (given sufficient access permissions). It's up to the developer to prevent this from happening, and is easy enough to do from the application.
|
|
|
|
|
Helllo everyBody,
Just wanna to say that clients can access any web Page or any website and try to download that file.and then the isp should detect this file and stop it.
best regards
dghdfghdfghdfghdgh
|
|
|
|
|
Eh? Do you mean that you don't want anybody to be able to rip your website? If so, there's no simple way to stop this (and in some cases it's impossible).
|
|
|
|
|
hey plz Mr. O'Hanlon i need ur help.
We have some files that exist in some sites that help some clients to activate my application.
i thaught that if i speak with the isp provider to prevent this persons from downloading this files, it seems a solution to my problem.
Note that i don't have any website.
Some one tell me to use a proxy server and disallow these files from being downloaded.
do you have any suggestion plz?
best regards
dghdfghdfghdfghdgh
|
|
|
|
|
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 21: static MemberPhotoConfiguration()
Line 22: {
Line 23: dbConnectionString = ConfigurationManager.ConnectionStrings["MemberPhotoConnection"].ConnectionString;
Line 24: dbProviderName = ConfigurationManager.ConnectionStrings["MemberPhotoConnection"].ProviderName;
Line 25: productsPerPage = Int32.Parse(ConfigurationManager.AppSettings["ProductsPerPage"]);
Source File: c:\Inetpub\wwwroot\MemberPhoto\App_Code\MemberPhotoConfiguration.cs Line: 23
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
MemberPhotoConfiguration..cctor() in c:\Inetpub\wwwroot\MemberPhoto\App_Code\MemberPhotoConfiguration.cs:23
[TypeInitializationException: The type initializer for 'MemberPhotoConfiguration' threw an exception.]
MemberPhotoConfiguration.get_DbProviderName() in c:\Inetpub\wwwroot\MemberPhoto\App_Code\MemberPhotoConfiguration.cs:45
GenericDataAccess.CreateCommand() in c:\Inetpub\wwwroot\MemberPhoto\App_Code\GenericDataAccess.cs:111
CatalogAccess.GetDepartments() in c:\Inetpub\wwwroot\MemberPhoto\App_Code\CatalogAccess.cs:54
DepartmentsList.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\MemberPhoto\UserControls\DepartmentsList.ascx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
|
|
|
|