Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-21-2017, 10:19 PM
gmayor's Avatar
gmayor gmayor is offline randomize numbers. help me defeat plagiarism! Windows 10 randomize numbers. help me defeat plagiarism! Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

This looks fun, but it will take some thought how to record who has which version, but something along the lines of the following may help get you started.

Code:
Option Explicit
Private Const sName As String = "Billy|Bobby|John|Susan|Ted"
Private Const sPlace As String = "Cliff|Tower|Bridge"
Private Const sItem As String = "Stone|Rock|Wrench"
Private vName As Variant, vPlace As Variant, vItem As Variant
Private iPlace As Integer, iName As Integer, iItem As Integer
Private iHeight As Integer, iMass As Integer
Private sText As String

Private Function RandomNumber(Lowest As Long, Highest As Long, _
                              Optional Decimals As Integer) As Integer
    If IsMissing(Decimals) Or Decimals = 0 Then
        Randomize
        RandomNumber = Int((Highest + 1 - Lowest) * Rnd + Lowest)
    Else
        Randomize
        RandomNumber = Round((Highest - Lowest) * Rnd + Lowest, Decimals)
    End If
End Function

Sub Macro1()
    vName = Split(sName, "|")
    vPlace = Split(sPlace, "|")
    vItem = Split(sItem, "|")
    iHeight = RandomNumber(1, 50, 0)
    iMass = RandomNumber(1, 5, 0)
    iPlace = RandomNumber(0, UBound(vPlace))
    iName = RandomNumber(0, UBound(vName))
    iItem = RandomNumber(0, UBound(vItem))
    sText = vName(iName) & " dropped a " & vItem(iItem) & " off a " & iHeight & " meter-high " & _
            vPlace(iPlace) & ". The " & vItem(iItem) & " has a mass of " & iMass & " kilograms."
    Selection.TypeText sText
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Tags
word 2016



Other Forums: Access Forums

All times are GMT -7. The time now is 04:45 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft