Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2005, 02:28 AM
Authorized User
 
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sajid_pk Send a message via Yahoo to sajid_pk
Default Random Number generation

Hi Friends,

I want to generate 25 distinct randam alphanumeric characters in one ASP.NET page. I am using following code
private int GenerateRandomNumber(){
Thread.Sleep( 1 );
Random r = new Random(DateTime.Now.Millisecond);
int a=0;
while (!( (a>=48 && a<=57) ||(a>=65 && a<=90) ||(a>=97 && a<=122)))
{
a = r.Next(123);
intNumber += 1;
}
return a;}

But this function always produces same 25 characters. Any idea?
 
Old May 10th, 2005, 03:22 AM
Authorized User
 
Join Date: May 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have made this using asp 3.0 maybe this will work on ASP.Net

try this one.

<%
'Generate Unique Random Numbers

Dim ctrLoop,flagVal,rndNum,arryLoop,storageVal(255),fn dLoop,statArray,countDown(10),setCount

ctrLoop=1
setCount=1

for arryLoop=1 to 100

    if ctrLoop<>11 then
        RS.MoveFirst
        flagVal=0

        Randomize
        rndNum=int(50*Rnd())+1
        storageVal(arryLoop) = rndNum

        statArray=arryLoop-1


        if rndNum<51 then
            for fndLoop=1 to statArray
                if storageVal(arryLoop)=storageVal(fndLoop) then flagVal=1
            next
        else
            'greater than 50
        end if


        if flagVal=0 then
            'Response.Write rndNum & "<br>"
            countDown(setCount)=rndNum-1

            setCount=setCount+1
            ctrLoop=ctrLoop+1

        else
            'flagVal is 0
        end if

    else
        'Reached 10 items
    end if

Next

%>
 
Old May 19th, 2005, 02:12 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how about this simple script



    <%

        For Counter = 1 to 25

        randomize
        char=int(rnd*24)


        select case char

            case 1
            response.write "A "

            case 2
            response.write "B "

            case 3
            response.write "C "

            case 4
            response.write "D "

            case 5
            response.write "E "

            case 6
            response.write "F "

            case 7
            response.write "G "

            case 8
            response.write "H "

            case 9
            response.write "I "

            case 10
            response.write "J "

            case 11
            response.write "K "

            case 12
            response.write "L "

            case 13
            response.write "M "

            case 14
            response.write "N "

            case 15
            response.write "O "

            case 16
            response.write "P "

            case 17
            response.write "Q "

            case 18
            response.write "R "

            case 19
            response.write "S "

            case 20
            response.write "T "

            case 21
            response.write "U "

            case 22
            response.write "V "

            case 23
            response.write "W "

            case 24
            response.write "X "

            case 0
            response.write "Y "

        End Select

        Next

    %>

 
Old May 19th, 2005, 02:15 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

your "for/next" has to be outside the function






Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Number Generation i_shahid C# 2005 2 March 31st, 2008 10:50 PM
Generation of alphanumeric random characters sajid_pk ASP.NET 1.0 and 1.1 Professional 1 May 10th, 2005 08:37 AM
random file generation Ashleek007 Beginning PHP 1 February 24th, 2005 03:20 AM
random number rajuru Beginning PHP 7 December 7th, 2004 10:52 AM
Random Generation of Username and Password Prabhakar_dt Classic ASP Basics 2 August 31st, 2004 06:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.