Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default random number generation


how would I write code to generate a random number only between 1-3
say with whole nubmers such as 1,2,3, 4 etc

thank

--
nyn0
-----------------------------------------------------------------------
nyn04's Profile: http://www.excelforum.com/member.php...fo&userid=1265
View this thread: http://www.excelforum.com/showthread.php?threadid=26231

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default random number generation

Dude,

You can do something like:

Sub test()
MsgBox Int((30 - 1 + 1) * Rnd + 1)
End Sub

This will generate random numbers between 1 and 30.

regards,
Robert
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 837
Default random number generation

Also see replys under your separate thread in
microsoft.public.excel.misc. Please do not separately post the same
question to multiple newsgroups.

Jerry

nyn04 wrote:

how would I write code to generate a random number only between 1-30
say with whole nubmers such as 1,2,3, 4 etc

thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default random number generation

nyn04

' Another way a little more random see "Randomize Statement"
' vba or vb help

Private Sub Label1_Click()
Dim n
' Initialize random-number generator.
' Uses the system timer
Randomize
' Generate random value between 1 and in this case 30.
n = Int((30 * Rnd) + 1)
Label1.Caption = n

End Sub


Good Luck
TK



wrote:

how would I write code to generate a random number only between 1-30
say with whole nubmers such as 1,2,3, 4 etc

thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for Random Number Generation krisinvincible Excel Worksheet Functions 3 May 7th 07 12:41 AM
random number generation Ahmad Excel Discussion (Misc queries) 3 November 6th 06 06:27 PM
random number generation DSpec Excel Worksheet Functions 7 October 3rd 05 01:41 PM
I need help with random number generation David Stoddard Excel Worksheet Functions 10 March 28th 05 07:06 AM
random number generation kurtrambis Excel Worksheet Functions 1 November 1st 04 09:23 PM


All times are GMT +1. The time now is 03:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"