在kotlin中,是否有现成的随机性来源?是否是标准java.util.Random、kotlin.math.random*或基本当前时间millis的一些实现,可以用来创建自己的随机数生成器?我什么都找不到。
如果不存在,那么在不设置您自己的平台相关实现的情况下,如何获得随机性的来源?这是我唯一需要的方法:
expect class Rng {
fun nextInt(): Int
}
我想让它成为不可知论者。
目前正在做一项小小的学校作业,试图弄清楚是否有一种特定的方法可以从随机数组中打印出项目。老师希望我们在1到100的范围内生成200个随机数,存储它们,然后打印每个范围的数量(10,20,30,等等)。我已经完成了随机化和存储,但我有一个小问题,试图找出如何正确地显示这些。
我们应该用1-10,11-20等随机数来区分它们,但也要用旁边的直方图来区分。我想我可以很好地计算出柱状图,但我需要一些帮助来显示每个范围的数字!我希望这是有意义的,任何帮助都是感激的!
到目前为止,我得到的非常简单,只是很难弄清楚println()中的内容。
fun main() {
val rnds = (1..
我在Android Studio中使用kotlin。我正在编写一个简单的程序来显示一系列随机数,每个随机数之间的延迟为1秒。RandNumText是on框的名称。我尝试了以下几点:
i = 1
while (i < 10) {
RandNumText.text = ((0..9).random()).toString()
for (j in 0 until 50000) {}
i++
}
i = 1
while (i < 10) {
RandNumText.text = ((0..9).random()).toString()
Thread
我试图从(key, value)中的hashmap中随机选择一个kotlin对象。我在下面创建了hashmap。
val tips = hashMapOf("Having a balanced diet is the key" to "Have nutritious foods like vegetables and fruits along with legumes, whole wheat, cereals etc."
, "Fluids will help you manage" to "Drink suff
在jvm (scala、java、kotlin、jruby等)上,在一个变量中得到以下结果,这些变量被反复查询以获得新的随机值:
IntStream.range(0,10).forEach( __ -> System.out.println(rand.nextFloat()));
在python中是否有一个与nextFloat\双\Int等价的?如果不是,在调用时引擎盖下会发生什么
import random
for i in range(10):
print(str(random.random()))
random库本身是否持有单个随机引用?如果没有,那么如何确保我们避免重复,比
当我试图执行以下代码时:
fun main(args: Array<String>) {
val x = BigInteger.ONE
var y = BigInteger.TEN
val z = x + y;
}
我要犯这个错误,出什么事了?我和1.0.0-beta-1038-IJ143-19一起工作
Error:(7, 15) Kotlin: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
p
我在Gradle下创建了新的Kotlin项目。默认情况下,它将此依赖项设置为Kotlin-库项目。我想知道这个kotlin-bom lib是做什么的?
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotli
虽然运行一个颤振的应用程序,我面临失败,而格拉德尔建设。这个问题之前并没有出现,似乎是随机发生的。我不知道我要怎么做才能解决这个问题!
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve or
在从beta07更新到beta08之后构建代码时,执行失败并返回NullPointerException。 下面是完整的堆栈跟踪: e: java.lang.NullPointerException
at org.jetbrains.kotlin.ir.util.IrUtilsKt.getTypeSubstitutionMap(IrUtils.kt:548)
at org.jetbrains.kotlin.ir.util.IrUtilsKt.getTypeSubstitutionMap(IrUtils.kt:556)
at androidx.compose.compiler.plugins.
我正在开发一个应用程序,使用IntelliJ IDEA集成开发环境中的Kotlin语言和Gradle Build。我收到以下错误:
Exception in thread "main" kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath
at kotlin.jvm.internal.ClassReferenc
我正在使用Kotlin多平台(JVM & JS),它在IDEA中创建了三个项目:demo、demo-js和demo-jvm。
我想将公共代码分成更多的子项目/子模块。假设我添加了commonmod;如何使其编译?
现在,对于gradle run -p demo-jvm,错误是:
demo/demo-js/src/main/kotlin/demo/commonmod/example.kt: (3, 12): Actual function 'getPlatform' has no corresponding expected declaration
但是我认为我这样做是完
我已经将kotlin-reflect库添加到我的Android项目中,现在Proguard正在生成数百行注释,列出了所有具有名为INSTANCE的字段的类,其中当然包括每一个Kotlin object。
这只是Proguard输出的一小部分:
Note: kotlin.reflect.jvm.internal.KClassImpl$Data$objectInstance$2 accesses a declared field 'INSTANCE' dynamically
Maybe this is program field 'co.zsmb.example
将jetpack compose添加到我的应用程序后,如:所述,我在构建时看到以下错误:
Could not perform incremental compilation: Could not connect to Kotlin compile daemon
Could not connect to kotlin daemon. Using fallback strategy.
exception: java.lang.NoSuchMethodError: org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEv
我正在尝试用gradle kotlin DSL作为IntelliJ idea中的构建系统来设置一个kotlin项目,但是当我尝试运行buil.gradle.kts文件时,我得到了下面的错误。我尝试过不同的kotlin编译器版本,但没有成功。 warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatib
当我在android studio中运行我的第一个flutter应用程序时,我得到了这个错误。我的模拟器网络已连接,并且飞行模式已关闭。我看到了其他类似的问题,但它们都不像这个错误,它们对我没有帮助。有谁可以帮我?
Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
Could not resolve compiler classpath. Check if Kotlin Gradle plugin repository is conf
今天我刚刚更新了我的Android Studio
Android Studio 3.5.2
Build #AI-191.8026.42.35.5977832, built on October 31, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.1
我更新了Android Studio,因为当kotlin版本低于1.3.60时,它会向我提示错误。
然而,我遇到了单元测试文件的问题。以前,我可以毫无问题地运行单元测试