- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试根据我想要的数量启动一组随机数。到目前为止,我确实编写了一个代码,但是我缺少一个循环来删除重复项并用新数字替换这些重复项,再次检查重复项,删除并重复。
到目前为止,我有这个,但循环部分给我带来了问题。
Sub PEM()
' Perguntas de Escolha Multipla
Dim MyRange As Range
Dim lMin As Long, lMax As Long
Dim dRand As Double
' Se 1 questão
If ActiveSheet.Range("B7").Value = 1 Then Set MyRange = ActiveSheet.Range("O1")
' Se 2 questão
If ActiveSheet.Range("B7").Value = 2 Then Set MyRange = ActiveSheet.Range("O1:O2")
' Se 3 questão
If ActiveSheet.Range("B7").Value = 3 Then Set MyRange = ActiveSheet.Range("O1:O3")
' Se 4 questão
If ActiveSheet.Range("B7").Value = 4 Then Set MyRange = ActiveSheet.Range("O1:O4")
' Se 5 questão
If ActiveSheet.Range("B7").Value = 5 Then Set MyRange = ActiveSheet.Range("O1:O5")
' Se 6 questão
If ActiveSheet.Range("B7").Value = 6 Then Set MyRange = ActiveSheet.Range("O1:O6")
' Se 7 questão
If ActiveSheet.Range("B7").Value = 7 Then Set MyRange = ActiveSheet.Range("O1:O7")
' Se 8 questão
If ActiveSheet.Range("B7").Value = 8 Then Set MyRange = ActiveSheet.Range("O1:O8")
' Se 9 questão
If ActiveSheet.Range("B7").Value = 9 Then Set MyRange = ActiveSheet.Range("O1:O9")
' Se 10 questão
If ActiveSheet.Range("B7").Value = 10 Then Set MyRange = ActiveSheet.Range("O1:O10")
' Se 11 questão
If ActiveSheet.Range("B7").Value = 11 Then Set MyRange = ActiveSheet.Range("O1:O11")
' Se 12 questão
If ActiveSheet.Range("B7").Value = 12 Then Set MyRange = ActiveSheet.Range("O1:O12")
' Se 13 questão
If ActiveSheet.Range("B7").Value = 13 Then Set MyRange = ActiveSheet.Range("O1:O13")
' Se 14 questão
If ActiveSheet.Range("B7").Value = 14 Then Set MyRange = ActiveSheet.Range("O1:O14")
' Se 15 questão
If ActiveSheet.Range("B7").Value = 15 Then Set MyRange = ActiveSheet.Range("O1:O15")
' Se 16 questão
If ActiveSheet.Range("B7").Value = 16 Then Set MyRange = ActiveSheet.Range("O1:O16")
' Se 17 questão
If ActiveSheet.Range("B7").Value = 17 Then Set MyRange = ActiveSheet.Range("O1:O17")
' Se 18 questão
If ActiveSheet.Range("B7").Value = 18 Then Set MyRange = ActiveSheet.Range("O1:O18")
' Se 19 questão
If ActiveSheet.Range("B7").Value = 19 Then Set MyRange = ActiveSheet.Range("O1:O19")
' Se 20 questão
If ActiveSheet.Range("B7").Value = 20 Then Set MyRange = ActiveSheet.Range("O1:O20")
' Se 21 questão
If ActiveSheet.Range("B7").Value = 21 Then Set MyRange = ActiveSheet.Range("O1:O21")
' Se 22 questão
If ActiveSheet.Range("B7").Value = 22 Then Set MyRange = ActiveSheet.Range("O1:O22")
' Se 23 questão
If ActiveSheet.Range("B7").Value = 23 Then Set MyRange = ActiveSheet.Range("O1:O23")
' Se 24 questão
If ActiveSheet.Range("B7").Value = 24 Then Set MyRange = ActiveSheet.Range("O1:O24")
' Se 25 questão
If ActiveSheet.Range("B7").Value = 25 Then Set MyRange = ActiveSheet.Range("O1:O25")
' Se 26 questão
If ActiveSheet.Range("B7").Value = 26 Then Set MyRange = ActiveSheet.Range("O1:O26")
' Se 27 questão
If ActiveSheet.Range("B7").Value = 27 Then Set MyRange = ActiveSheet.Range("O1:O27")
' Se 28 questão
If ActiveSheet.Range("B7").Value = 28 Then Set MyRange = ActiveSheet.Range("O1:O28")
' Se 29 questão
If ActiveSheet.Range("B7").Value = 29 Then Set MyRange = ActiveSheet.Range("O1:O29")
' Se 30 questão
If ActiveSheet.Range("B7").Value = 30 Then Set MyRange = ActiveSheet.Range("O1:O30")
' Se 31 questão
If ActiveSheet.Range("B7").Value = 31 Then Set MyRange = ActiveSheet.Range("O1:O31")
' Se 32 questão
If ActiveSheet.Range("B7").Value = 32 Then Set MyRange = ActiveSheet.Range("O1:O32")
' Se 33 questão
If ActiveSheet.Range("B7").Value = 33 Then Set MyRange = ActiveSheet.Range("O1:O33")
' Se 34 questão
If ActiveSheet.Range("B7").Value = 34 Then Set MyRange = ActiveSheet.Range("O1:O34")
' Se 35 questão
If ActiveSheet.Range("B7").Value = 35 Then Set MyRange = ActiveSheet.Range("O1:O35")
' Se 36 questão
If ActiveSheet.Range("B7").Value = 36 Then Set MyRange = ActiveSheet.Range("O1:O36")
' Se 37 questão
If ActiveSheet.Range("B7").Value = 37 Then Set MyRange = ActiveSheet.Range("O1:O37")
' Se 38 questão
If ActiveSheet.Range("B7").Value = 38 Then Set MyRange = ActiveSheet.Range("O1:O38")
' Se 39 questão
If ActiveSheet.Range("B7").Value = 39 Then Set MyRange = ActiveSheet.Range("O1:O39")
' Se 40 questão
If ActiveSheet.Range("B7").Value = 40 Then Set MyRange = ActiveSheet.Range("O1:O40")
' Se 41 questão
If ActiveSheet.Range("B7").Value = 41 Then Set MyRange = ActiveSheet.Range("O1:O41")
' Se 42 questão
If ActiveSheet.Range("B7").Value = 42 Then Set MyRange = ActiveSheet.Range("O1:O42")
' Se 43 questão
If ActiveSheet.Range("B7").Value = 43 Then Set MyRange = ActiveSheet.Range("O1:O43")
' Se 44 questão
If ActiveSheet.Range("B7").Value = 44 Then Set MyRange = ActiveSheet.Range("O1:O44")
' Se 45 questão
If ActiveSheet.Range("B7").Value = 45 Then Set MyRange = ActiveSheet.Range("O1:O45")
' Se 46 questão
If ActiveSheet.Range("B7").Value = 46 Then Set MyRange = ActiveSheet.Range("O1:O46")
' Se 47 questão
If ActiveSheet.Range("B7").Value = 47 Then Set MyRange = ActiveSheet.Range("O1:O47")
' Se 48 questão
If ActiveSheet.Range("B7").Value = 48 Then Set MyRange = ActiveSheet.Range("O1:O48")
' Se 49 questão
If ActiveSheet.Range("B7").Value = 49 Then Set MyRange = ActiveSheet.Range("O1:O49")
' Se 50 questão
If ActiveSheet.Range("B7").Value = 50 Then Set MyRange = ActiveSheet.Range("O1:O50")
' Lança valor mínimo (1) e máximo (número total de perguntas sobre o tema na base de dados)
lMin = 1
lMax = ActiveSheet.Range("N1")
Randomize
For Each C In MyRange.Cells
' Calculate random value, where
' Value >= Min And Value <= Max
dRand = Rnd * (lMax - lMin) + lMin
' Use the following line only if the random
' value should be an integer
dRand = Int(dRand)
C.Value = dRand
Next C
'Apagar duplicados
ActiveSheet.Range("O1:O50").RemoveDuplicates Columns:=Array(1)
'Loop
For Each C In MyRange.Cells
Do While IsEmpty(C)
If IsEmpty(C) Then
dRand = Rnd * (lMax - lMin) + lMin
' Calculate random value, where
' Value >= Min And Value <= Max
' Use the following line only if the random
' value should be an integer
dRand = Int(dRand)
C.Value = dRand
Loop
End Sub
最佳答案
由于您拥有 Office 365,我们可以使用 RANDARRAY:
可以直接将公式放入O1
它会溢出:
=INDEX(UNIQUE(RANDARRAY(1000,1,1,N1,TRUE)),SEQUENCE(B7))
Sub PEM()
Dim rng As Range
Set rng = ActiveSheet.Range("O1:O50")
rng.ClearContents
ActiveSheet.Range("O1").Formula2 = "=INDEX(UNIQUE(RANDARRAY(1000,1,1,N1,TRUE)),SEQUENCE(B7))"
rng.Value = rng.Value
End Sub
它将放入公式,然后将其替换为仅值,因此它保持静态。
关于excel - 生成随机数时循环替换重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68732652/
我编写了一个函数来随机从 [-10,10] 中获取一对。 import System.Random main = do { s State g a randomSt = S
好的,我了解如何在 Scala 中实现随机数生成器以及如何设置生成的随机数的上限,但我对如何更改下限感到困惑。例如: var computerGuess= scala.util.Random
我写了一个函数来从 [-10,10] 中随机得到一对。 import System.Random main = do { s State g a randomSt = St
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我正在做一个项目,我需要在其中生成 8 个随机数。由于某种原因,我遇到随机数部分非常耗时的问题。 8 个随机数的意思是我需要一个由数字 0-9 组成的 8 个字符长的字符串。例如 01234567 或
这个问题已经有答案了: Why do I always get the same sequence of random numbers with rand()? (12 个回答) 已关闭 9 年前。
我看到这个问题可能已经在这里得到回答:Random using WELL512 但是,它对用户不太友好,也没有提供如何在“真实世界”的代码片段中使用它的示例。 这是我目前拥有的: #define m
我想知道是否有人可以为我澄清这一行。 Create a function die(x) which rolls a die x times keeping track of how many time
我正在制作一款有 6 名防守球员的足球比赛。我将这段代码设置为随机让他们都向四分卫移动。 我想知道是否有更好的方法来做到这一点。我知道必须有一种方法可以在没有这么多 if 语句的情况下循环它,但我对
在以下位置:http://www.fredosaurus.com/notes-cpp/misc/random.html 它提到如果我们想生成一个1-10范围内的随机数,我们可以这样做: r = (ra
如何在 Linux 和 C++ 中使用随机数? 我找到了一些我想使用的代码,它有一行 srand((unsigned)time(0));//seed 但是 gcc 说 board.cpp:94:24:
这个问题在这里已经有了答案: Generating random whole numbers in JavaScript in a specific range (40 个答案) 关闭 9 年前。
我有以下脚本: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1;
利用oracle的dbms_random包结合rownum来实现,示例如下,随机取499户: select * from ( select * from busi.t_ar_
我需要获取随机数,但它不应该等于之前的数字。这是我的一段代码。但这不起作用。 function getNumber(){ var min = 0; var max = 4; var i;
我对 Haskell 还很陌生。我有一个数据类型: data Sentence= Prop Int | No Sentence | And [Sentence]
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
这个问题已经有答案了: How do I generate random integers within a specific range in Java? (73 个回答) 已关闭 7 年前。
function getRandomArbitrary(min, max) { var r = Math.floor(Math.random() * (max - min + 1) + m
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Generate random number with non-uniform density 我尝试识别/
我是一名优秀的程序员,十分优秀!