Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Random number generator
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Random number generator

 Post Reply Post Reply Page  12>
Author
Nathan View Drop Down
Groupie
Groupie


Joined: 08 January 2002
Location: Greece
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nathan Quote  Post ReplyReply Direct Link To This Post Topic: Random number generator
    Posted: 28 December 2003 at 10:26am

I am trying to create an asp random number generator which will provide a number between 1 and 16:

<% 
Dim maxlinks=16
Randomize Timer
linksCode = ((9275 * CInt((RND * 32000) + 1000)) mod maxlinks)+1
%>

The code is used to select random links to be inlcuded on each page of my web site. The includes part can be seen working here:
http://www.corfu-travel-guide.info/includes/random_links.asp

The problem is, it doesn't seem very random! Other programmers I have spoken to have also had similar problems in creating a random number with VB - can anyone help.

Thanks

Nathan

 

 

 

Back to Top
Paul Lush View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 24 September 2003
Status: Offline
Points: 59
Post Options Post Options   Thanks (0) Thanks(0)   Quote Paul Lush Quote  Post ReplyReply Direct Link To This Post Posted: 29 December 2003 at 4:12am

<%

randomize

response.write rnd(maxlinks) + 1

%>

maybe just a little too simple....

Back to Top
Nathan View Drop Down
Groupie
Groupie


Joined: 08 January 2002
Location: Greece
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nathan Quote  Post ReplyReply Direct Link To This Post Posted: 04 January 2004 at 12:08pm

Thanks Paul.

 

I have tried working with the code:
<%
dim i
for i = 1 to 10
randomize
response.write rnd(16) + 1
response.write "<HR>"
next
%>

This can be see working here:

http://www.corfu-travel-guide.info/includes/rand.asp

But the results are as follows ( I am after just a result of a random number between 1-16) Thanks for any help you can offer.:

1.115078


1.032219
1.811956
1.207165
1.021537
1.844
1.111033
1.309933
1.978812
1.972176

 

 

Back to Top
psycotik View Drop Down
Groupie
Groupie


Joined: 27 November 2003
Status: Offline
Points: 73
Post Options Post Options   Thanks (0) Thanks(0)   Quote psycotik Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2004 at 2:23am

It might be due to you using mod. that its less random.

if you do a random number from 0 to maxlinks you might have a better randomness.

Back to Top
Nathan View Drop Down
Groupie
Groupie


Joined: 08 January 2002
Location: Greece
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nathan Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2004 at 3:53pm

I'm not using MOD in the above script. All I am after is a random number between 1 and 16. Seems so simple, but I cannot seen to write the script.

Must be turkey I ate at Christmas - or the beer - it's clouding my mind.

Nathan

 

Back to Top
psycotik View Drop Down
Groupie
Groupie


Joined: 27 November 2003
Status: Offline
Points: 73
Post Options Post Options   Thanks (0) Thanks(0)   Quote psycotik Quote  Post ReplyReply Direct Link To This Post Posted: 05 January 2004 at 10:35pm

Try this...

Randomize Timer
RandNumber = CLng(Rnd * (maxlinks - 1)) + 1

Back to Top
Flamewave View Drop Down
Senior Member
Senior Member
Avatar

Joined: 19 June 2002
Location: United States
Status: Offline
Points: 376
Post Options Post Options   Thanks (0) Thanks(0)   Quote Flamewave Quote  Post ReplyReply Direct Link To This Post Posted: 07 January 2004 at 10:42am
something like CInt(Rnd * 1000) Mod 16 should do the trick, then put in a check to see if the number is bigger then 16, if it is, set it to 16.
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.
Back to Top
earchiee View Drop Down
Newbie
Newbie


Joined: 08 January 2004
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote earchiee Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2004 at 12:04am
I need to create a 6 digit random number every time my page is loaded can any one help please.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.